]> granicus.if.org Git - neomutt/commitdiff
flatten ifs
authorRichard Russon <rich@flatcap.org>
Thu, 26 Apr 2018 20:22:39 +0000 (21:22 +0100)
committerRichard Russon <rich@flatcap.org>
Thu, 26 Apr 2018 20:22:39 +0000 (21:22 +0100)
21 files changed:
commands.c
conn/socket.c
conn/ssl.c
curs_main.c
group.c
hook.c
imap/message.c
imap/utf7.c
init.c
menu.c
mh.c
mutt/date.c
mutt/file.c
mutt_lua.c
mutt_notmuch.c
ncrypt/crypt.c
ncrypt/crypt_gpgme.c
newsrc.c
recvattach.c
sendlib.c
signal.c

index 95468dd0f6a1bc3e3dc344780b63ae1ce7073f5e..e0804b5bd1cf51b70ba3558d219f990d36221ea3 100644 (file)
@@ -628,24 +628,24 @@ void mutt_shell_escape(void)
   char buf[LONG_STRING];
 
   buf[0] = '\0';
-  if (mutt_get_field(_("Shell command: "), buf, sizeof(buf), MUTT_CMD) == 0)
-  {
-    if (!buf[0] && Shell)
-      mutt_str_strfcpy(buf, Shell, sizeof(buf));
-    if (buf[0])
-    {
-      mutt_window_clearline(MuttMessageWindow, 0);
-      mutt_endwin();
-      fflush(stdout);
-      int rc = mutt_system(buf);
-      if (rc == -1)
-        mutt_debug(1, "Error running \"%s\"!", buf);
-
-      if ((rc != 0) || WaitKey)
-        mutt_any_key_to_continue(NULL);
-      mutt_buffy_check(true);
-    }
-  }
+  if (mutt_get_field(_("Shell command: "), buf, sizeof(buf), MUTT_CMD) != 0)
+    return;
+
+  if (!buf[0] && Shell)
+    mutt_str_strfcpy(buf, Shell, sizeof(buf));
+  if (!buf[0])
+    return;
+
+  mutt_window_clearline(MuttMessageWindow, 0);
+  mutt_endwin();
+  fflush(stdout);
+  int rc = mutt_system(buf);
+  if (rc == -1)
+    mutt_debug(1, "Error running \"%s\"!", buf);
+
+  if ((rc != 0) || WaitKey)
+    mutt_any_key_to_continue(NULL);
+  mutt_buffy_check(true);
 }
 
 /**
index 36fe1bacaa05bd7ec558b7f892ebefd1f6285499..fb496885e4b371c04333d57bc8c574866e24596c 100644 (file)
@@ -73,18 +73,18 @@ struct ConnectionList *mutt_socket_head(void)
  */
 static int socket_preconnect(void)
 {
-  if (mutt_str_strlen(Preconnect))
+  if (!Preconnect)
+    return 0;
+
+  mutt_debug(2, "Executing preconnect: %s\n", Preconnect);
+  const int rc = mutt_system(Preconnect);
+  mutt_debug(2, "Preconnect result: %d\n", rc);
+  if (rc != 0)
   {
-    mutt_debug(2, "Executing preconnect: %s\n", Preconnect);
-    const int rc = mutt_system(Preconnect);
-    mutt_debug(2, "Preconnect result: %d\n", rc);
-    if (rc != 0)
-    {
-      const int save_errno = errno;
-      mutt_perror(_("Preconnect command failed."));
+    const int save_errno = errno;
+    mutt_perror(_("Preconnect command failed."));
 
-      return save_errno;
-    }
+    return save_errno;
   }
 
   return 0;
index 7b0dcfb745744da31724a92df8241f11f9cb8f71..cb6a4f8941f59dc56c7d4562e311dd3d56ec5349 100644 (file)
@@ -503,26 +503,27 @@ static bool compare_certificates(X509 *cert, X509 *peercert,
  */
 static bool check_certificate_expiration(X509 *peercert, bool silent)
 {
-  if (SslVerifyDates != MUTT_NO)
+  if (SslVerifyDates == MUTT_NO)
+    return true;
+
+  if (X509_cmp_current_time(X509_get_notBefore(peercert)) >= 0)
   {
-    if (X509_cmp_current_time(X509_get_notBefore(peercert)) >= 0)
+    if (!silent)
     {
-      if (!silent)
-      {
-        mutt_debug(2, "Server certificate is not yet valid\n");
-        mutt_error(_("Server certificate is not yet valid"));
-      }
-      return false;
+      mutt_debug(2, "Server certificate is not yet valid\n");
+      mutt_error(_("Server certificate is not yet valid"));
     }
-    if (X509_cmp_current_time(X509_get_notAfter(peercert)) <= 0)
+    return false;
+  }
+
+  if (X509_cmp_current_time(X509_get_notAfter(peercert)) <= 0)
+  {
+    if (!silent)
     {
-      if (!silent)
-      {
-        mutt_debug(2, "Server certificate has expired\n");
-        mutt_error(_("Server certificate has expired"));
-      }
-      return false;
+      mutt_debug(2, "Server certificate has expired\n");
+      mutt_error(_("Server certificate has expired"));
     }
+    return false;
   }
 
   return true;
@@ -684,18 +685,18 @@ static int ssl_socket_write(struct Connection *conn, const char *buf, size_t len
  */
 static void ssl_get_client_cert(struct SslSockData *ssldata, struct Connection *conn)
 {
-  if (SslClientCert)
-  {
-    mutt_debug(2, "Using client certificate %s\n", SslClientCert);
-    SSL_CTX_set_default_passwd_cb_userdata(ssldata->ctx, &conn->account);
-    SSL_CTX_set_default_passwd_cb(ssldata->ctx, ssl_passwd_cb);
-    SSL_CTX_use_certificate_file(ssldata->ctx, SslClientCert, SSL_FILETYPE_PEM);
-    SSL_CTX_use_PrivateKey_file(ssldata->ctx, SslClientCert, SSL_FILETYPE_PEM);
-
-    /* if we are using a client cert, SASL may expect an external auth name */
-    if (mutt_account_getuser(&conn->account) < 0)
-      mutt_debug(1, "Couldn't get user info\n");
-  }
+  if (!SslClientCert)
+    return;
+
+  mutt_debug(2, "Using client certificate %s\n", SslClientCert);
+  SSL_CTX_set_default_passwd_cb_userdata(ssldata->ctx, &conn->account);
+  SSL_CTX_set_default_passwd_cb(ssldata->ctx, ssl_passwd_cb);
+  SSL_CTX_use_certificate_file(ssldata->ctx, SslClientCert, SSL_FILETYPE_PEM);
+  SSL_CTX_use_PrivateKey_file(ssldata->ctx, SslClientCert, SSL_FILETYPE_PEM);
+
+  /* if we are using a client cert, SASL may expect an external auth name */
+  if (mutt_account_getuser(&conn->account) < 0)
+    mutt_debug(1, "Couldn't get user info\n");
 }
 
 /**
@@ -706,9 +707,7 @@ static void ssl_get_client_cert(struct SslSockData *ssldata, struct Connection *
  */
 static int ssl_socket_close_and_restore(struct Connection *conn)
 {
-  int rc;
-
-  rc = ssl_socket_close(conn);
+  int rc = ssl_socket_close(conn);
   conn->conn_read = raw_socket_read;
   conn->conn_write = raw_socket_write;
   conn->conn_close = raw_socket_close;
index 78e3e2c217031e46274f7533843afcfdc7938ac2..33a8964745b190118492c317762749e7c0f42a62 100644 (file)
@@ -229,37 +229,37 @@ static int ci_previous_undeleted(int msgno)
  */
 static int ci_first_message(void)
 {
-  if (Context && Context->msgcount)
-  {
-    int old = -1;
-    for (int i = 0; i < Context->vcount; i++)
-    {
-      if (!Context->hdrs[Context->v2r[i]]->read &&
-          !Context->hdrs[Context->v2r[i]]->deleted)
-      {
-        if (!Context->hdrs[Context->v2r[i]]->old)
-          return i;
-        else if (old == -1)
-          old = i;
-      }
-    }
-    if (old != -1)
-      return old;
+  if (!Context || !Context->msgcount)
+    return 0;
 
-    /* If Sort is reverse and not threaded, the latest message is first.
-     * If Sort is threaded, the latest message is first iff exactly one
-     * of Sort and SortAux are reverse.
-     */
-    if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
-        ((Sort & SORT_MASK) == SORT_THREADS && ((Sort ^ SortAux) & SORT_REVERSE)))
-    {
-      return 0;
-    }
-    else
+  int old = -1;
+  for (int i = 0; i < Context->vcount; i++)
+  {
+    if (!Context->hdrs[Context->v2r[i]]->read && !Context->hdrs[Context->v2r[i]]->deleted)
     {
-      return (Context->vcount ? Context->vcount - 1 : 0);
+      if (!Context->hdrs[Context->v2r[i]]->old)
+        return i;
+      else if (old == -1)
+        old = i;
     }
   }
+  if (old != -1)
+    return old;
+
+  /* If Sort is reverse and not threaded, the latest message is first.
+   * If Sort is threaded, the latest message is first iff exactly one
+   * of Sort and SortAux are reverse.
+   */
+  if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
+      ((Sort & SORT_MASK) == SORT_THREADS && ((Sort ^ SortAux) & SORT_REVERSE)))
+  {
+    return 0;
+  }
+  else
+  {
+    return (Context->vcount ? Context->vcount - 1 : 0);
+  }
+
   return 0;
 }
 
diff --git a/group.c b/group.c
index f92150b63e6d5f9bf7d41bb7474b389c3a958463..75f82c29be7f7b48fc61fa39c91a5d227c33393d 100644 (file)
--- a/group.c
+++ b/group.c
@@ -188,15 +188,14 @@ int mutt_group_context_remove_regex(struct GroupContext *ctx, const char *s)
 
 bool mutt_group_match(struct Group *g, const char *s)
 {
-  struct Address *ap = NULL;
+  if (!g || !s)
+    return false;
 
-  if (s && g)
-  {
-    if (mutt_regexlist_match(g->rs, s))
+  if (mutt_regexlist_match(g->rs, s))
+    return true;
+  for (struct Address *ap = g->as; ap; ap = ap->next)
+    if (ap->mailbox && (mutt_str_strcasecmp(s, ap->mailbox) == 0))
       return true;
-    for (ap = g->as; ap; ap = ap->next)
-      if (ap->mailbox && (mutt_str_strcasecmp(s, ap->mailbox) == 0))
-        return true;
-  }
+
   return false;
 }
diff --git a/hook.c b/hook.c
index d7eac9504b6c29441811d2815b88262b94884db4..a910f05a37eedf6a437f1c971686490fa4c5608a 100644 (file)
--- a/hook.c
+++ b/hook.c
@@ -527,28 +527,28 @@ static int addr_hook(char *path, size_t pathlen, int type, struct Context *ctx,
 void mutt_default_save(char *path, size_t pathlen, struct Header *hdr)
 {
   *path = '\0';
-  if (addr_hook(path, pathlen, MUTT_SAVEHOOK, Context, hdr) != 0)
+  if (addr_hook(path, pathlen, MUTT_SAVEHOOK, Context, hdr) == 0)
+    return;
+
+  struct Address *addr = NULL;
+  struct Envelope *env = hdr->env;
+  bool from_me = mutt_addr_is_user(env->from);
+
+  if (!from_me && env->reply_to && env->reply_to->mailbox)
+    addr = env->reply_to;
+  else if (!from_me && env->from && env->from->mailbox)
+    addr = env->from;
+  else if (env->to && env->to->mailbox)
+    addr = env->to;
+  else if (env->cc && env->cc->mailbox)
+    addr = env->cc;
+  else
+    addr = NULL;
+  if (addr)
   {
-    struct Address *addr = NULL;
-    struct Envelope *env = hdr->env;
-    bool from_me = mutt_addr_is_user(env->from);
-
-    if (!from_me && env->reply_to && env->reply_to->mailbox)
-      addr = env->reply_to;
-    else if (!from_me && env->from && env->from->mailbox)
-      addr = env->from;
-    else if (env->to && env->to->mailbox)
-      addr = env->to;
-    else if (env->cc && env->cc->mailbox)
-      addr = env->cc;
-    else
-      addr = NULL;
-    if (addr)
-    {
-      char tmp[_POSIX_PATH_MAX];
-      mutt_safe_path(tmp, sizeof(tmp), addr);
-      snprintf(path, pathlen, "=%s", tmp);
-    }
+    char tmp[_POSIX_PATH_MAX];
+    mutt_safe_path(tmp, sizeof(tmp), addr);
+    snprintf(path, pathlen, "=%s", tmp);
   }
 }
 
index ce82b4015ab06dcfa31d9a964dedabe8b7dc324b..18f08348c88570978a0e8928d7ef706526be1b50 100644 (file)
@@ -579,18 +579,18 @@ static void set_changed_flag(struct Context *ctx, struct Header *h,
    * cmd_parse_fetch().  We don't want to count a local modification
    * to the header flag as a "change".
    */
-  if ((old_hd_flag != new_hd_flag) || (!local_changes))
-  {
-    if (new_hd_flag != h_flag)
-    {
-      if (server_changes)
-        *server_changes = 1;
+  if ((old_hd_flag == new_hd_flag) && local_changes)
+    return;
 
-      /* Local changes have priority */
-      if (!local_changes)
-        mutt_set_flag(ctx, h, flag_name, new_hd_flag);
-    }
-  }
+  if (new_hd_flag == h_flag)
+    return;
+
+  if (server_changes)
+    *server_changes = 1;
+
+  /* Local changes have priority */
+  if (!local_changes)
+    mutt_set_flag(ctx, h, flag_name, new_hd_flag);
 }
 
 /**
@@ -1580,13 +1580,13 @@ int imap_cache_clean(struct ImapData *idata)
  */
 void imap_free_header_data(struct ImapHeaderData **data)
 {
-  if (*data)
-  {
-    /* this should be safe even if the list wasn't used */
-    FREE(&((*data)->flags_system));
-    FREE(&((*data)->flags_remote));
-    FREE(data);
-  }
+  if (!data || !*data)
+    return;
+
+  /* this should be safe even if the list wasn't used */
+  FREE(&((*data)->flags_system));
+  FREE(&((*data)->flags_remote));
+  FREE(data);
 }
 
 /**
index a7d9854c353c247e3bcc2cd4020db67d68768ce1..3a38c68e70c3037b54b6a966ececff4baca537de 100644 (file)
@@ -317,19 +317,19 @@ bail:
  */
 void imap_utf_encode(struct ImapData *idata, char **s)
 {
-  if (Charset)
+  if (!Charset || !s)
+    return;
+
+  char *t = mutt_str_strdup(*s);
+  if (t && (mutt_ch_convert_string(&t, Charset, "utf-8", 0) == 0))
   {
-    char *t = mutt_str_strdup(*s);
-    if (t && mutt_ch_convert_string(&t, Charset, "utf-8", 0) == 0)
-    {
-      FREE(s);
-      if (idata->unicode)
-        *s = mutt_str_strdup(t);
-      else
-        *s = utf8_to_utf7(t, strlen(t), NULL, 0);
-    }
-    FREE(&t);
+    FREE(s);
+    if (idata->unicode)
+      *s = mutt_str_strdup(t);
+    else
+      *s = utf8_to_utf7(t, strlen(t), NULL, 0);
   }
+  FREE(&t);
 }
 
 /**
@@ -339,21 +339,21 @@ void imap_utf_encode(struct ImapData *idata, char **s)
  */
 void imap_utf_decode(struct ImapData *idata, char **s)
 {
+  if (!Charset)
+    return;
+
   char *t = NULL;
 
-  if (Charset)
-  {
-    if (idata->unicode)
-      t = mutt_str_strdup(*s);
-    else
-      t = utf7_to_utf8(*s, strlen(*s), 0, 0);
+  if (idata->unicode)
+    t = mutt_str_strdup(*s);
+  else
+    t = utf7_to_utf8(*s, strlen(*s), 0, 0);
 
-    if (t && mutt_ch_convert_string(&t, "utf-8", Charset, 0) == 0)
-    {
-      FREE(s);
-      *s = t;
-    }
-    else
-      FREE(&t);
+  if (t && mutt_ch_convert_string(&t, "utf-8", Charset, 0) == 0)
+  {
+    FREE(s);
+    *s = t;
   }
+  else
+    FREE(&t);
 }
diff --git a/init.c b/init.c
index c440b8b787ed60308723bfb2119c8f52cbdd308c..e406590ad6405000e5edcd873c36cd328a0ec83d 100644 (file)
--- a/init.c
+++ b/init.c
@@ -3080,16 +3080,16 @@ finish:
 
 static void matches_ensure_morespace(int current)
 {
-  if (current > MatchesListsize - 2)
-  {
-    int base_space = MAX(NUMVARS, NUMCOMMANDS) + 1;
-    int extra_space = MatchesListsize - base_space;
-    extra_space *= 2;
-    const int space = base_space + extra_space;
-    mutt_mem_realloc(&Matches, space * sizeof(char *));
-    memset(&Matches[current + 1], 0, space - current);
-    MatchesListsize = space;
-  }
+  if (current <= (MatchesListsize - 2))
+    return;
+
+  int base_space = MAX(NUMVARS, NUMCOMMANDS) + 1;
+  int extra_space = MatchesListsize - base_space;
+  extra_space *= 2;
+  const int space = base_space + extra_space;
+  mutt_mem_realloc(&Matches, space * sizeof(char *));
+  memset(&Matches[current + 1], 0, space - current);
+  MatchesListsize = space;
 }
 
 /**
@@ -3106,19 +3106,19 @@ static void candidate(char *dest, char *try, const char *src, size_t len)
   if (!dest || !try || !src)
     return;
 
-  if (strstr(src, try) == src)
+  if (strstr(src, try) != src)
+    return;
+
+  matches_ensure_morespace(NumMatched);
+  Matches[NumMatched++] = src;
+  if (dest[0] == 0)
+    mutt_str_strfcpy(dest, src, len);
+  else
   {
-    matches_ensure_morespace(NumMatched);
-    Matches[NumMatched++] = src;
-    if (dest[0] == 0)
-      mutt_str_strfcpy(dest, src, len);
-    else
-    {
-      int l;
-      for (l = 0; src[l] && src[l] == dest[l]; l++)
-        ;
-      dest[l] = '\0';
-    }
+    int l;
+    for (l = 0; src[l] && src[l] == dest[l]; l++)
+      ;
+    dest[l] = '\0';
   }
 }
 
diff --git a/menu.c b/menu.c
index e19a5970b53a8a7c71866eab9d7e6a9294a90d52..51ba7380906f73b9dabf4bae14672e9df5f7d9cf 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -472,20 +472,20 @@ void menu_redraw_current(struct Menu *menu)
 
 static void menu_redraw_prompt(struct Menu *menu)
 {
-  if (menu->dialog)
+  if (!menu || !menu->dialog)
+    return;
+
+  if (OptMsgErr)
   {
-    if (OptMsgErr)
-    {
-      mutt_sleep(1);
-      OptMsgErr = false;
-    }
+    mutt_sleep(1);
+    OptMsgErr = false;
+  }
 
-    if (ErrorBufMessage)
-      mutt_clear_error();
+  if (ErrorBufMessage)
+    mutt_clear_error();
 
-    mutt_window_mvaddstr(menu->messagewin, 0, 0, menu->prompt);
-    mutt_window_clrtoeol(menu->messagewin);
-  }
+  mutt_window_mvaddstr(menu->messagewin, 0, 0, menu->prompt);
+  mutt_window_clrtoeol(menu->messagewin);
 }
 
 void menu_check_recenter(struct Menu *menu)
@@ -667,11 +667,11 @@ void menu_half_up(struct Menu *menu)
 
 void menu_top_page(struct Menu *menu)
 {
-  if (menu->current != menu->top)
-  {
-    menu->current = menu->top;
-    menu->redraw = REDRAW_MOTION;
-  }
+  if (menu->current == menu->top)
+    return;
+
+  menu->current = menu->top;
+  menu->redraw = REDRAW_MOTION;
 }
 
 void menu_bottom_page(struct Menu *menu)
diff --git a/mh.c b/mh.c
index 35e47ea8fd71567da66260382734cae99c40352e..4bb4dd20fa1130e7f4a885a4ffe572edae6ec379 100644 (file)
--- a/mh.c
+++ b/mh.c
@@ -107,16 +107,16 @@ static inline struct MhData *mh_data(struct Context *ctx)
 
 static void mhs_alloc(struct MhSequences *mhs, int i)
 {
-  if (i > mhs->max || !mhs->flags)
-  {
-    const int newmax = i + 128;
-    int j = mhs->flags ? mhs->max + 1 : 0;
-    mutt_mem_realloc(&mhs->flags, sizeof(mhs->flags[0]) * (newmax + 1));
-    while (j <= newmax)
-      mhs->flags[j++] = 0;
+  if ((i <= mhs->max) && mhs->flags)
+    return;
 
-    mhs->max = newmax;
-  }
+  const int newmax = i + 128;
+  int j = mhs->flags ? mhs->max + 1 : 0;
+  mutt_mem_realloc(&mhs->flags, sizeof(mhs->flags[0]) * (newmax + 1));
+  while (j <= newmax)
+    mhs->flags[j++] = 0;
+
+  mhs->max = newmax;
 }
 
 static void mhs_free_sequences(struct MhSequences *mhs)
@@ -818,13 +818,12 @@ struct Header *maildir_parse_message(int magic, const char *fname, bool is_old,
                                      struct Header *h)
 {
   FILE *f = fopen(fname, "r");
-  if (f)
-  {
-    h = maildir_parse_stream(magic, f, fname, is_old, h);
-    mutt_file_fclose(&f);
-    return h;
-  }
-  return NULL;
+  if (!f)
+    return NULL;
+
+  h = maildir_parse_stream(magic, f, fname, is_old, h);
+  mutt_file_fclose(&f);
+  return h;
 }
 
 static int maildir_parse_dir(struct Context *ctx, struct Maildir ***last,
index c0aa89cb6b3f031c91c60e11c1960e14a52bd18b..79bb9836f684b30a034fa1c5dc6bd005934da852 100644 (file)
@@ -160,12 +160,11 @@ static time_t compute_tz(time_t g, struct tm *utc)
  */
 static int is_leap_year_feb(struct tm *tm)
 {
-  if (tm->tm_mon == 1)
-  {
-    int y = tm->tm_year + 1900;
-    return (((y & 3) == 0) && (((y % 100) != 0) || ((y % 400) == 0)));
-  }
-  return 0;
+  if (tm->tm_mon != 1)
+    return 0;
+
+  int y = tm->tm_year + 1900;
+  return (((y & 3) == 0) && (((y % 100) != 0) || ((y % 400) == 0)));
 }
 
 /**
index b3e69ab4b6c977f71141f8fef917ff7323e09ec9..2017523d789450e1f0143ad55d90e35698ebae86 100644 (file)
@@ -166,20 +166,20 @@ int mutt_file_fclose(FILE **f)
  */
 int mutt_file_fsync_close(FILE **f)
 {
+  if (!f || !*f)
+    return 0;
+
   int r = 0;
 
-  if (*f)
+  if (fflush(*f) || fsync(fileno(*f)))
   {
-    if (fflush(*f) || fsync(fileno(*f)))
-    {
-      int save_errno = errno;
-      r = -1;
-      mutt_file_fclose(f);
-      errno = save_errno;
-    }
-    else
-      r = mutt_file_fclose(f);
+    int save_errno = errno;
+    r = -1;
+    mutt_file_fclose(f);
+    errno = save_errno;
   }
+  else
+    r = mutt_file_fclose(f);
 
   return r;
 }
index a78b590b5c26530446461dc7ab2f64baea21ccd1..e21cb6b6612ff31514d134b3d4a10c031af693b3 100644 (file)
@@ -363,23 +363,23 @@ static void luaopen_mutt(lua_State *l)
 
 static bool lua_init(lua_State **l)
 {
+  if (l && *l)
+    return true;
+
+  mutt_debug(2, " * lua_init()\n");
+  *l = luaL_newstate();
+
   if (!*l)
   {
-    mutt_debug(2, " * lua_init()\n");
-    *l = luaL_newstate();
-
-    if (!*l)
-    {
-      mutt_error("Error: Couldn't load the lua interpreter.");
-      return false;
-    }
+    mutt_error("Error: Couldn't load the lua interpreter.");
+    return false;
+  }
 
-    lua_atpanic(*l, handle_panic);
+  lua_atpanic(*l, handle_panic);
 
-    /* load various Lua libraries */
-    luaL_openlibs(*l);
-    luaopen_mutt(*l);
-  }
+  /* load various Lua libraries */
+  luaL_openlibs(*l);
+  luaopen_mutt(*l);
 
   return true;
 }
index dcfc7e57debb212fc0a5a125a0b5d3b4c0869c16..8c3490ddfebf73e2524560214b9592e39d08e5d7 100644 (file)
@@ -598,13 +598,13 @@ static notmuch_database_t *get_db(struct NmCtxData *data, bool writable)
 {
   if (!data)
     return NULL;
-  if (!data->db)
-  {
-    const char *db_filename = get_db_filename(data);
+  if (data->db)
+    return data->db;
+
+  const char *db_filename = get_db_filename(data);
+  if (db_filename)
+    data->db = do_database_open(db_filename, writable, true);
 
-    if (db_filename)
-      data->db = do_database_open(db_filename, writable, true);
-  }
   return data->db;
 }
 
@@ -616,20 +616,18 @@ static notmuch_database_t *get_db(struct NmCtxData *data, bool writable)
  */
 static int release_db(struct NmCtxData *data)
 {
-  if (data && data->db)
-  {
-    mutt_debug(1, "nm: db close\n");
+  if (!data || !data->db)
+    return -1;
+
+  mutt_debug(1, "nm: db close\n");
 #ifdef NOTMUCH_API_3
-    notmuch_database_destroy(data->db);
+  notmuch_database_destroy(data->db);
 #else
-    notmuch_database_close(data->db);
+  notmuch_database_close(data->db);
 #endif
-    data->db = NULL;
-    data->longrun = false;
-    return 0;
-  }
-
-  return -1;
+  data->db = NULL;
+  data->longrun = false;
+  return 0;
 }
 
 /**
@@ -644,16 +642,14 @@ static int db_trans_begin(struct NmCtxData *data)
   if (!data || !data->db)
     return -1;
 
-  if (!data->trans)
-  {
-    mutt_debug(2, "nm: db trans start\n");
-    if (notmuch_database_begin_atomic(data->db))
-      return -1;
-    data->trans = true;
-    return 1;
-  }
+  if (data->trans)
+    return 0;
 
-  return 0;
+  mutt_debug(2, "nm: db trans start\n");
+  if (notmuch_database_begin_atomic(data->db))
+    return -1;
+  data->trans = true;
+  return 1;
 }
 
 /**
@@ -667,13 +663,13 @@ static int db_trans_end(struct NmCtxData *data)
   if (!data || !data->db)
     return -1;
 
-  if (data->trans)
-  {
-    mutt_debug(2, "nm: db trans end\n");
-    data->trans = false;
-    if (notmuch_database_end_atomic(data->db))
-      return -1;
-  }
+  if (!data->trans)
+    return 0;
+
+  mutt_debug(2, "nm: db trans end\n");
+  data->trans = false;
+  if (notmuch_database_end_atomic(data->db))
+    return -1;
 
   return 0;
 }
@@ -1724,24 +1720,25 @@ done:
  */
 static unsigned int count_query(notmuch_database_t *db, const char *qstr)
 {
-  unsigned int res = 0;
   notmuch_query_t *q = notmuch_query_create(db, qstr);
+  if (!q)
+    return 0;
 
-  if (q)
-  {
-    apply_exclude_tags(q);
+  unsigned int res = 0;
+
+  apply_exclude_tags(q);
 #if LIBNOTMUCH_CHECK_VERSION(5, 0, 0)
-    if (notmuch_query_count_messages(q, &res) != NOTMUCH_STATUS_SUCCESS)
-      res = 0; /* may not be defined on error */
+  if (notmuch_query_count_messages(q, &res) != NOTMUCH_STATUS_SUCCESS)
+    res = 0; /* may not be defined on error */
 #elif LIBNOTMUCH_CHECK_VERSION(4, 3, 0)
-    if (notmuch_query_count_messages_st(q, &res) != NOTMUCH_STATUS_SUCCESS)
-      res = 0; /* may not be defined on error */
+  if (notmuch_query_count_messages_st(q, &res) != NOTMUCH_STATUS_SUCCESS)
+    res = 0; /* may not be defined on error */
 #else
-    res = notmuch_query_count_messages(q);
+  res = notmuch_query_count_messages(q);
 #endif
-    notmuch_query_destroy(q);
-    mutt_debug(1, "nm: count '%s', result=%d\n", qstr, res);
-  }
+  notmuch_query_destroy(q);
+  mutt_debug(1, "nm: count '%s', result=%d\n", qstr, res);
+
   return res;
 }
 
index 68d6396ad9ad55da1eb34c48737bcc5e4c881402..8e33817dc2a7c12e16a72b634beb1cda13047e1a 100644 (file)
@@ -353,20 +353,18 @@ int mutt_is_multipart_signed(struct Body *b)
 
 int mutt_is_multipart_encrypted(struct Body *b)
 {
-  if (WithCrypto & APPLICATION_PGP)
-  {
-    char *p = NULL;
+  if ((WithCrypto & APPLICATION_PGP) == 0)
+    return 0;
 
-    if (!b || b->type != TYPEMULTIPART || !b->subtype ||
-        (mutt_str_strcasecmp(b->subtype, "encrypted") != 0) ||
-        !(p = mutt_param_get(&b->parameter, "protocol")) ||
-        (mutt_str_strcasecmp(p, "application/pgp-encrypted") != 0))
-      return 0;
+  char *p = NULL;
 
-    return PGPENCRYPT;
-  }
+  if (!b || b->type != TYPEMULTIPART || !b->subtype ||
+      (mutt_str_strcasecmp(b->subtype, "encrypted") != 0) ||
+      !(p = mutt_param_get(&b->parameter, "protocol")) ||
+      (mutt_str_strcasecmp(p, "application/pgp-encrypted") != 0))
+    return 0;
 
-  return 0;
+  return PGPENCRYPT;
 }
 
 int mutt_is_valid_multipart_pgp_encrypted(struct Body *b)
@@ -499,62 +497,62 @@ int mutt_is_application_smime(struct Body *m)
   if (!m)
     return 0;
 
-  if ((m->type & TYPEAPPLICATION) && m->subtype)
+  if (((m->type & TYPEAPPLICATION) == 0) || !m->subtype)
+    return 0;
+
+  char *t = NULL;
+  bool complain = false;
+  /* S/MIME MIME types don't need x- anymore, see RFC2311 */
+  if ((mutt_str_strcasecmp(m->subtype, "x-pkcs7-mime") == 0) ||
+      (mutt_str_strcasecmp(m->subtype, "pkcs7-mime") == 0))
   {
-    char *t = NULL;
-    bool complain = false;
-    /* S/MIME MIME types don't need x- anymore, see RFC2311 */
-    if ((mutt_str_strcasecmp(m->subtype, "x-pkcs7-mime") == 0) ||
-        (mutt_str_strcasecmp(m->subtype, "pkcs7-mime") == 0))
+    t = mutt_param_get(&m->parameter, "smime-type");
+    if (t)
     {
-      t = mutt_param_get(&m->parameter, "smime-type");
-      if (t)
-      {
-        if (mutt_str_strcasecmp(t, "enveloped-data") == 0)
-          return SMIMEENCRYPT;
-        else if (mutt_str_strcasecmp(t, "signed-data") == 0)
-          return (SMIMESIGN | SMIMEOPAQUE);
-        else
-          return 0;
-      }
-      /* Netscape 4.7 uses
-       * Content-Description: S/MIME Encrypted Message
-       * instead of Content-Type parameter
-       */
-      if (mutt_str_strcasecmp(m->description, "S/MIME Encrypted Message") == 0)
+      if (mutt_str_strcasecmp(t, "enveloped-data") == 0)
         return SMIMEENCRYPT;
-      complain = true;
+      else if (mutt_str_strcasecmp(t, "signed-data") == 0)
+        return (SMIMESIGN | SMIMEOPAQUE);
+      else
+        return 0;
     }
-    else if (mutt_str_strcasecmp(m->subtype, "octet-stream") != 0)
-      return 0;
+    /* Netscape 4.7 uses
+      * Content-Description: S/MIME Encrypted Message
+      * instead of Content-Type parameter
+      */
+    if (mutt_str_strcasecmp(m->description, "S/MIME Encrypted Message") == 0)
+      return SMIMEENCRYPT;
+    complain = true;
+  }
+  else if (mutt_str_strcasecmp(m->subtype, "octet-stream") != 0)
+    return 0;
 
-    t = mutt_param_get(&m->parameter, "name");
+  t = mutt_param_get(&m->parameter, "name");
 
-    if (!t)
-      t = m->d_filename;
-    if (!t)
-      t = m->filename;
-    if (!t)
-    {
-      if (complain)
-        mutt_message(
-            _("S/MIME messages with no hints on content are unsupported."));
-      return 0;
-    }
+  if (!t)
+    t = m->d_filename;
+  if (!t)
+    t = m->filename;
+  if (!t)
+  {
+    if (complain)
+      mutt_message(
+          _("S/MIME messages with no hints on content are unsupported."));
+    return 0;
+  }
 
-    /* no .p7c, .p10 support yet. */
+  /* no .p7c, .p10 support yet. */
 
-    size_t len = mutt_str_strlen(t) - 4;
-    if (len > 0 && *(t + len) == '.')
-    {
-      len++;
-      if (mutt_str_strcasecmp((t + len), "p7m") == 0)
-        /* Not sure if this is the correct thing to do, but
-         it's required for compatibility with Outlook */
-        return (SMIMESIGN | SMIMEOPAQUE);
-      else if (mutt_str_strcasecmp((t + len), "p7s") == 0)
-        return (SMIMESIGN | SMIMEOPAQUE);
-    }
+  size_t len = mutt_str_strlen(t) - 4;
+  if (len > 0 && *(t + len) == '.')
+  {
+    len++;
+    if (mutt_str_strcasecmp((t + len), "p7m") == 0)
+      /* Not sure if this is the correct thing to do, but
+        it's required for compatibility with Outlook */
+      return (SMIMESIGN | SMIMEOPAQUE);
+    else if (mutt_str_strcasecmp((t + len), "p7s") == 0)
+      return (SMIMESIGN | SMIMEOPAQUE);
   }
 
   return 0;
index 7be7fa5f5aadfbcbd2b6f94e8fdb892010bb9338..f9d94a6bcae16c8a79e914a9f327d6e03e6557b2 100644 (file)
@@ -4805,15 +4805,15 @@ static void init_common(void)
   /* this initialization should only run one time, but it may be called by
    * either pgp_gpgme_init or smime_gpgme_init */
   static bool has_run = false;
-  if (!has_run)
-  {
-    gpgme_check_version(NULL);
-    gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
+  if (has_run)
+    return;
+
+  gpgme_check_version(NULL);
+  gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
 #ifdef ENABLE_NLS
-    gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL));
+  gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL));
 #endif
-    has_run = true;
-  }
+  has_run = true;
 }
 
 static void init_pgp(void)
index 9f36874c4c9faffa269e09d93f345d34f62a7cb4..08e6a39b929459c9c55f1bfae9e19f2d5de9ef6d 100644 (file)
--- a/newsrc.c
+++ b/newsrc.c
@@ -72,26 +72,26 @@ struct BodyCache;
 static struct NntpData *nntp_data_find(struct NntpServer *nserv, const char *group)
 {
   struct NntpData *nntp_data = mutt_hash_find(nserv->groups_hash, group);
-
-  if (!nntp_data)
+  if (nntp_data)
+    return nntp_data;
+
+  size_t len = strlen(group) + 1;
+  /* create NntpData structure and add it to hash */
+  nntp_data = mutt_mem_calloc(1, sizeof(struct NntpData) + len);
+  nntp_data->group = (char *) nntp_data + sizeof(struct NntpData);
+  mutt_str_strfcpy(nntp_data->group, group, len);
+  nntp_data->nserv = nserv;
+  nntp_data->deleted = true;
+  mutt_hash_insert(nserv->groups_hash, nntp_data->group, nntp_data);
+
+  /* add NntpData to list */
+  if (nserv->groups_num >= nserv->groups_max)
   {
-    size_t len = strlen(group) + 1;
-    /* create NntpData structure and add it to hash */
-    nntp_data = mutt_mem_calloc(1, sizeof(struct NntpData) + len);
-    nntp_data->group = (char *) nntp_data + sizeof(struct NntpData);
-    mutt_str_strfcpy(nntp_data->group, group, len);
-    nntp_data->nserv = nserv;
-    nntp_data->deleted = true;
-    mutt_hash_insert(nserv->groups_hash, nntp_data->group, nntp_data);
-
-    /* add NntpData to list */
-    if (nserv->groups_num >= nserv->groups_max)
-    {
-      nserv->groups_max *= 2;
-      mutt_mem_realloc(&nserv->groups_list, nserv->groups_max * sizeof(nntp_data));
-    }
-    nserv->groups_list[nserv->groups_num++] = nntp_data;
+    nserv->groups_max *= 2;
+    mutt_mem_realloc(&nserv->groups_list, nserv->groups_max * sizeof(nntp_data));
   }
+  nserv->groups_list[nserv->groups_num++] = nntp_data;
+
   return nntp_data;
 }
 
index 7ea552ec1cf369b86b68364eac808983b66b033a..03e129c1d225de328dad8ee4de7cdc4afcdb5683 100644 (file)
@@ -889,22 +889,22 @@ static int recvattach_pgp_check_traditional(struct AttachCtx *actx, struct Menu
 static void recvattach_edit_content_type(struct AttachCtx *actx,
                                          struct Menu *menu, struct Header *hdr)
 {
-  if (mutt_edit_content_type(hdr, CURATTACH->content, CURATTACH->fp) == 1)
+  if (mutt_edit_content_type(hdr, CURATTACH->content, CURATTACH->fp) != 1)
+    return;
+
+  /* The mutt_update_recvattach_menu() will overwrite any changes
+   * made to a decrypted CURATTACH->content, so warn the user. */
+  if (CURATTACH->decrypted)
   {
-    /* The mutt_update_recvattach_menu() will overwrite any changes
-     * made to a decrypted CURATTACH->content, so warn the user. */
-    if (CURATTACH->decrypted)
-    {
-      mutt_message(
-          _("Structural changes to decrypted attachments are not supported"));
-      mutt_sleep(1);
-    }
-    /* Editing the content type can rewrite the body structure. */
-    for (int i = 0; i < actx->idxlen; i++)
-      actx->idx[i]->content = NULL;
-    mutt_actx_free_entries(actx);
-    mutt_update_recvattach_menu(actx, menu, 1);
+    mutt_message(
+        _("Structural changes to decrypted attachments are not supported"));
+    mutt_sleep(1);
   }
+  /* Editing the content type can rewrite the body structure. */
+  for (int i = 0; i < actx->idxlen; i++)
+    actx->idx[i]->content = NULL;
+  mutt_actx_free_entries(actx);
+  mutt_update_recvattach_menu(actx, menu, 1);
 }
 
 int mutt_attach_display_loop(struct Menu *menu, int op, struct Header *hdr,
index 4f70856cd458f2bf96f2b354655c4fdb7d52a5bb..9c88733a4a39e67be0c8f744757ba0a1fd78d120 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -2213,25 +2213,23 @@ static void encode_headers(struct ListHead *h)
 
 const char *mutt_fqdn(short may_hide_host)
 {
-  char *p = NULL;
+  if (!Hostname || (Hostname[0] == '@'))
+    return NULL;
 
-  if (Hostname && Hostname[0] != '@')
-  {
-    p = Hostname;
+  char *p = Hostname;
 
-    if (may_hide_host && HiddenHost)
-    {
-      p = strchr(Hostname, '.');
-      if (p)
-        p++;
+  if (may_hide_host && HiddenHost)
+  {
+    p = strchr(Hostname, '.');
+    if (p)
+      p++;
 
-      /* sanity check: don't hide the host if
-       * the fqdn is something like detebe.org.
-       */
+    /* sanity check: don't hide the host if
+      * the fqdn is something like detebe.org.
+      */
 
-      if (!p || !strchr(p, '.'))
-        p = Hostname;
-    }
+    if (!p || !strchr(p, '.'))
+      p = Hostname;
   }
 
   return p;
index ec720a5f51838bebc358c98a8c0abeda4adac73e..e14b21f61950493182e3ab9c180d8ca104cfa6ac 100644 (file)
--- a/signal.c
+++ b/signal.c
@@ -173,17 +173,17 @@ void mutt_signal_init(void)
  */
 void mutt_block_signals(void)
 {
-  if (!OptSignalsBlocked)
-  {
-    sigemptyset(&Sigset);
-    sigaddset(&Sigset, SIGTERM);
-    sigaddset(&Sigset, SIGHUP);
-    sigaddset(&Sigset, SIGTSTP);
-    sigaddset(&Sigset, SIGINT);
-    sigaddset(&Sigset, SIGWINCH);
-    sigprocmask(SIG_BLOCK, &Sigset, 0);
-    OptSignalsBlocked = true;
-  }
+  if (OptSignalsBlocked)
+    return;
+
+  sigemptyset(&Sigset);
+  sigaddset(&Sigset, SIGTERM);
+  sigaddset(&Sigset, SIGHUP);
+  sigaddset(&Sigset, SIGTSTP);
+  sigaddset(&Sigset, SIGINT);
+  sigaddset(&Sigset, SIGWINCH);
+  sigprocmask(SIG_BLOCK, &Sigset, 0);
+  OptSignalsBlocked = true;
 }
 
 /**
@@ -191,56 +191,56 @@ void mutt_block_signals(void)
  */
 void mutt_unblock_signals(void)
 {
-  if (OptSignalsBlocked)
-  {
-    sigprocmask(SIG_UNBLOCK, &Sigset, 0);
-    OptSignalsBlocked = false;
-  }
+  if (!OptSignalsBlocked)
+    return;
+
+  sigprocmask(SIG_UNBLOCK, &Sigset, 0);
+  OptSignalsBlocked = false;
 }
 
 void mutt_block_signals_system(void)
 {
   struct sigaction sa;
 
-  if (!OptSysSignalsBlocked)
-  {
-    /* POSIX: ignore SIGINT and SIGQUIT & block SIGCHLD  before exec */
-    sa.sa_handler = SIG_IGN;
-    sa.sa_flags = 0;
-    sigemptyset(&sa.sa_mask);
-    sigaction(SIGINT, &sa, &SysOldInt);
-    sigaction(SIGQUIT, &sa, &SysOldQuit);
+  if (OptSysSignalsBlocked)
+    return;
 
-    sigemptyset(&SigsetSys);
-    sigaddset(&SigsetSys, SIGCHLD);
-    sigprocmask(SIG_BLOCK, &SigsetSys, 0);
-    OptSysSignalsBlocked = true;
-  }
+  /* POSIX: ignore SIGINT and SIGQUIT & block SIGCHLD  before exec */
+  sa.sa_handler = SIG_IGN;
+  sa.sa_flags = 0;
+  sigemptyset(&sa.sa_mask);
+  sigaction(SIGINT, &sa, &SysOldInt);
+  sigaction(SIGQUIT, &sa, &SysOldQuit);
+
+  sigemptyset(&SigsetSys);
+  sigaddset(&SigsetSys, SIGCHLD);
+  sigprocmask(SIG_BLOCK, &SigsetSys, 0);
+  OptSysSignalsBlocked = true;
 }
 
 void mutt_unblock_signals_system(int catch)
 {
-  if (OptSysSignalsBlocked)
+  if (!OptSysSignalsBlocked)
+    return;
+
+  sigprocmask(SIG_UNBLOCK, &SigsetSys, NULL);
+  if (catch)
   {
-    sigprocmask(SIG_UNBLOCK, &SigsetSys, NULL);
-    if (catch)
-    {
-      sigaction(SIGQUIT, &SysOldQuit, NULL);
-      sigaction(SIGINT, &SysOldInt, NULL);
-    }
-    else
-    {
-      struct sigaction sa;
-
-      sa.sa_handler = SIG_DFL;
-      sigemptyset(&sa.sa_mask);
-      sa.sa_flags = 0;
-      sigaction(SIGQUIT, &sa, NULL);
-      sigaction(SIGINT, &sa, NULL);
-    }
-
-    OptSysSignalsBlocked = false;
+    sigaction(SIGQUIT, &SysOldQuit, NULL);
+    sigaction(SIGINT, &SysOldInt, NULL);
   }
+  else
+  {
+    struct sigaction sa;
+
+    sa.sa_handler = SIG_DFL;
+    sigemptyset(&sa.sa_mask);
+    sa.sa_flags = 0;
+    sigaction(SIGQUIT, &sa, NULL);
+    sigaction(SIGINT, &sa, NULL);
+  }
+
+  OptSysSignalsBlocked = false;
 }
 
 void mutt_allow_interrupt(int disposition)