NeoMutt  2020-06-26-89-g172cd3
Teaching an old dog new tricks
DOXYGEN
from.c File Reference

Determine who the email is from. More...

#include "config.h"
#include <stdbool.h>
#include <stdio.h>
#include <time.h>
#include "mutt/lib.h"
#include "from.h"
+ Include dependency graph for from.c:

Go to the source code of this file.

Functions

bool is_from (const char *s, char *path, size_t pathlen, time_t *tp)
 Is a string a 'From' header line? More...
 

Detailed Description

Determine who the email is from.

Authors
  • Michael R. Elkins

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file from.c.

Function Documentation

◆ is_from()

bool is_from ( const char *  s,
char *  path,
size_t  pathlen,
time_t *  tp 
)

Is a string a 'From' header line?

Parameters
[in]sString to test
[out]pathBuffer for extracted path
[in]pathlenLength of buffer
[out]tpExtracted time
Return values
1Yes, it is
0No, it isn't

A valid message separator looks like: From <return-path> <weekday> <month> <day> <time> <year>

Definition at line 48 of file from.c.

49 {
50  bool lax = false;
51 
52  const regmatch_t *match = mutt_prex_capture(PREX_MBOX_FROM, s);
53  if (!match)
54  {
56  if (!match)
57  {
58  mutt_debug(LL_DEBUG1, "Could not parse From line: <%s>\n", s);
59  return false;
60  }
61  lax = true;
62  mutt_debug(LL_DEBUG2, "Fallback regex for From line: <%s>\n", s);
63  }
64 
65  if (path)
66  {
67  const regmatch_t *msender =
69  const size_t dsize = MIN(pathlen, mutt_regmatch_len(msender) + 1);
70  mutt_str_copy(path, s + mutt_regmatch_start(msender), dsize);
71  }
72 
73  if (tp)
74  {
75  // clang-format off
76  const regmatch_t *mmonth = &match[lax ? PREX_MBOX_FROM_LAX_MATCH_MONTH : PREX_MBOX_FROM_MATCH_MONTH];
77  const regmatch_t *mday = &match[lax ? PREX_MBOX_FROM_LAX_MATCH_DAY : PREX_MBOX_FROM_MATCH_DAY];
78  const regmatch_t *mtime = &match[lax ? PREX_MBOX_FROM_LAX_MATCH_TIME : PREX_MBOX_FROM_MATCH_TIME];
79  const regmatch_t *myear = &match[lax ? PREX_MBOX_FROM_LAX_MATCH_YEAR : PREX_MBOX_FROM_MATCH_YEAR];
80  // clang-format on
81 
82  struct tm tm = { 0 };
83  tm.tm_isdst = -1;
84  tm.tm_mon = mutt_date_check_month(s + mutt_regmatch_start(mmonth));
85  sscanf(s + mutt_regmatch_start(mday), " %d", &tm.tm_mday);
86  sscanf(s + mutt_regmatch_start(mtime), "%d:%d:%d", &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
87  int year = 0;
88  sscanf(s + mutt_regmatch_start(myear), "%d", &year);
89  if (year > 1900)
90  tm.tm_year = year - 1900;
91  else if (year < 70)
92  tm.tm_year = year + 100;
93  else
94  tm.tm_year = year;
95  *tp = mutt_date_make_time(&tm, false);
96  }
97 
98  return true;
99 }
#define MIN(a, b)
Definition: memory.h:31
static size_t mutt_regmatch_len(const regmatch_t *match)
Return the length of a match.
Definition: regex3.h:80
From [god at heaven.af.mil] Sat Jan 3 01:05:34 1996
Definition: prex.h:221
From god@heaven.af.mil Sat [Jan] 3 01:05:34 1996
Definition: prex.h:204
From god@heaven.af.mil Sat Jan 10 [01:05:34] 1996
Definition: prex.h:208
From god@heaven.af.mil Sat Jan 10 01:05:34 [1996]
Definition: prex.h:209
From god@heaven.af.mil Sat Jan 10 01:05:34 [1996]
Definition: prex.h:232
Log at debug level 2.
Definition: logging.h:41
From god@heaven.af.mil Sat Jan 10 [01:05:34] 1996
Definition: prex.h:228
From god@heaven.af.mil Sat [Jan] 3 01:05:34 1996
Definition: prex.h:224
From [god@heaven.af.mil] Sat Jan 3 01:05:34 1996
Definition: prex.h:202
From god@heaven.af.mil Sat Jan [ 3] 01:05:34 1996
Definition: prex.h:225
regmatch_t * mutt_prex_capture(enum Prex which, const char *str)
match a precompiled regex against a string
Definition: prex.c:306
static regoff_t mutt_regmatch_start(const regmatch_t *match)
Return the start of a match.
Definition: regex3.h:60
[From god@heaven.af.mil Sat Jan 3 01:05:34 1996]
Definition: prex.h:40
Log at debug level 1.
Definition: logging.h:40
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition: string.c:721
int mutt_date_check_month(const char *s)
Is the string a valid month name.
Definition: date.c:401
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
From god@heaven.af.mil Sat Jan [ 3] 01:05:34 1996
Definition: prex.h:205
time_t mutt_date_make_time(struct tm *t, bool local)
Convert struct tm to time_t
Definition: date.c:228
[From god@heaven.af.mil Sat Jan 3 01:05:34 1996]
Definition: prex.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function: