]> granicus.if.org Git - neomutt/commitdiff
tidy from
authorRichard Russon <rich@flatcap.org>
Sat, 14 Jul 2018 16:08:11 +0000 (17:08 +0100)
committerRichard Russon <rich@flatcap.org>
Mon, 16 Jul 2018 22:47:18 +0000 (23:47 +0100)
email/from.c
email/from.h

index 570ad06f6c74ef655720274be2d96747390f86f2..73e924bb5b43ca894a3e21ff0ac058f235b6c9ec 100644 (file)
@@ -45,7 +45,7 @@
  * A valid message separator looks like:
  * `From [ <return-path> ] <weekday> <month> <day> <time> [ <timezone> ] <year>`
  */
-int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
+bool is_from(const char *s, char *path, size_t pathlen, time_t *tp)
 {
   struct tm tm;
   int yr;
@@ -54,11 +54,11 @@ int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
     *path = '\0';
 
   if (mutt_str_strncmp("From ", s, 5) != 0)
-    return 0;
+    return false;
 
   s = mutt_str_next_word(s); /* skip over the From part. */
   if (!*s)
-    return 0;
+    return false;
 
   mutt_debug(3, "\nis_from(): parsing: %s\n", s);
 
@@ -72,7 +72,7 @@ int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
       if (*p == '\\')
       {
         if (*++p == '\0')
-          return 0;
+          return false;
       }
       else if (*p == '"')
       {
@@ -81,7 +81,7 @@ int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
     }
 
     if (q || !*p)
-      return 0;
+      return false;
 
     /* pipermail archives have the return_path obscured such as "me at neomutt.org" */
     if (mutt_str_strncasecmp(p, " at ", 4) == 0)
@@ -93,14 +93,14 @@ int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
                    "error parsing what appears to be a pipermail-style "
                    "obscured return_path: %s\n",
                    s);
-        return 0;
+        return false;
       }
     }
 
     if (path)
     {
       size_t len = (size_t)(p - s);
-      if (len + 1 > pathlen)
+      if ((len + 1) > pathlen)
         len = pathlen - 1;
       memcpy(path, s, len);
       path[len] = '\0';
@@ -110,18 +110,18 @@ int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
     s = p + 1;
     SKIPWS(s);
     if (!*s)
-      return 0;
+      return false;
 
     if (!mutt_date_is_day_name(s))
     {
       mutt_debug(1, " expected weekday, got: %s\n", s);
-      return 0;
+      return false;
     }
   }
 
   s = mutt_str_next_word(s);
   if (!*s)
-    return 0;
+    return false;
 
   /* do a quick check to make sure that this isn't really the day of the week.
    * this could happen when receiving mail from a local user whose login name
@@ -131,27 +131,27 @@ int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
   {
     s = mutt_str_next_word(s);
     if (!*s)
-      return 0;
+      return false;
   }
 
   /* now we should be on the month. */
   tm.tm_mon = mutt_date_check_month(s);
   if (tm.tm_mon < 0)
-    return 0;
+    return false;
 
   /* day */
   s = mutt_str_next_word(s);
   if (!*s)
-    return 0;
+    return false;
   if (sscanf(s, "%d", &tm.tm_mday) != 1)
-    return 0;
+    return false;
   if ((tm.tm_mday < 1) || (tm.tm_mday > 31))
-    return 0;
+    return false;
 
   /* time */
   s = mutt_str_next_word(s);
   if (!*s)
-    return 0;
+    return false;
 
   /* Accept either HH:MM or HH:MM:SS */
   if (sscanf(s, "%d:%d:%d", &tm.tm_hour, &tm.tm_min, &tm.tm_sec) == 3)
@@ -159,24 +159,24 @@ int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
   else if (sscanf(s, "%d:%d", &tm.tm_hour, &tm.tm_min) == 2)
     tm.tm_sec = 0;
   else
-    return 0;
+    return false;
 
   if ((tm.tm_hour < 0) || (tm.tm_hour > 23) || (tm.tm_min < 0) ||
       (tm.tm_min > 59) || (tm.tm_sec < 0) || (tm.tm_sec > 60))
   {
-    return 0;
+    return false;
   }
 
   s = mutt_str_next_word(s);
   if (!*s)
-    return 0;
+    return false;
 
   /* timezone? */
-  if (isalpha((unsigned char) *s) || *s == '+' || *s == '-')
+  if (isalpha((unsigned char) *s) || (*s == '+') || (*s == '-'))
   {
     s = mutt_str_next_word(s);
     if (!*s)
-      return 0;
+      return false;
 
     /*
      * some places have two timezone fields after the time, e.g.
@@ -186,16 +186,16 @@ int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
     {
       s = mutt_str_next_word(s);
       if (!*s)
-        return 0;
+        return false;
     }
   }
 
   /* year */
   if (sscanf(s, "%d", &yr) != 1)
-    return 0;
+    return false;
   if ((yr < 0) || (yr > 9999))
-    return 0;
-  tm.tm_year = yr > 1900 ? yr - 1900 : (yr < 70 ? yr + 100 : yr);
+    return false;
+  tm.tm_year = (yr > 1900) ? (yr - 1900) : ((yr < 70) ? (yr + 100) : yr);
 
   mutt_debug(3, "month=%d, day=%d, hr=%d, min=%d, sec=%d, yr=%d.\n", tm.tm_mon,
              tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_year);
@@ -204,5 +204,5 @@ int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
 
   if (tp)
     *tp = mutt_date_make_time(&tm, 0);
-  return 1;
+  return true;
 }
index 96cb76e9091bb6c6a2d62a3bb23ba29d408e5a56..c9f8db2f377468a1d85181b98c46ea77f8b68944 100644 (file)
@@ -26,6 +26,6 @@
 #include <stdio.h>
 #include <time.h>
 
-int is_from(const char *s, char *path, size_t pathlen, time_t *tp);
+bool is_from(const char *s, char *path, size_t pathlen, time_t *tp);
 
 #endif /* _EMAIL_FROM_H */