NeoMutt  2022-04-29-247-gc6aae8
Teaching an old dog new tricks
DOXYGEN
from.h File Reference

Determine who the email is from. More...

#include <stdbool.h>
#include <stdio.h>
#include <time.h>
+ Include dependency graph for from.h:
+ This graph shows which files directly or indirectly include this file:

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.h.

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 = &match[lax ? PREX_MBOX_FROM_LAX_MATCH_ENVSENDER : PREX_MBOX_FROM_MATCH_ENVSENDER];
68 const size_t dsize = MIN(pathlen, mutt_regmatch_len(msender) + 1);
69 mutt_str_copy(path, s + mutt_regmatch_start(msender), dsize);
70 }
71
72 if (tp)
73 {
74 // clang-format off
75 const regmatch_t *mmonth = &match[lax ? PREX_MBOX_FROM_LAX_MATCH_MONTH : PREX_MBOX_FROM_MATCH_MONTH];
76 const regmatch_t *mday = &match[lax ? PREX_MBOX_FROM_LAX_MATCH_DAY : PREX_MBOX_FROM_MATCH_DAY];
77 const regmatch_t *mtime = &match[lax ? PREX_MBOX_FROM_LAX_MATCH_TIME : PREX_MBOX_FROM_MATCH_TIME];
78 const regmatch_t *myear = &match[lax ? PREX_MBOX_FROM_LAX_MATCH_YEAR : PREX_MBOX_FROM_MATCH_YEAR];
79 // clang-format on
80
81 struct tm tm = { 0 };
82 tm.tm_isdst = -1;
83 tm.tm_mon = mutt_date_check_month(s + mutt_regmatch_start(mmonth));
84 sscanf(s + mutt_regmatch_start(mday), " %d", &tm.tm_mday);
85 sscanf(s + mutt_regmatch_start(mtime), "%d:%d:%d", &tm.tm_hour, &tm.tm_min, &tm.tm_sec);
86 int year = 0;
87 sscanf(s + mutt_regmatch_start(myear), "%d", &year);
88 if (year > 1900)
89 tm.tm_year = year - 1900;
90 else if (year < 70)
91 tm.tm_year = year + 100;
92 else
93 tm.tm_year = year;
94 *tp = mutt_date_make_time(&tm, false);
95 }
96
97 return true;
98}
time_t mutt_date_make_time(struct tm *t, bool local)
Convert struct tm to time_t
Definition: date.c:229
int mutt_date_check_month(const char *s)
Is the string a valid month name.
Definition: date.c:415
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
@ LL_DEBUG1
Log at debug level 1.
Definition: logging.h:40
#define MIN(a, b)
Definition: memory.h:31
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:652
regmatch_t * mutt_prex_capture(enum Prex which, const char *str)
Match a precompiled regex against a string.
Definition: prex.c:308
@ PREX_MBOX_FROM_LAX_MATCH_MONTH
From god@heaven.af.mil Sat [Jan] 3 01:05:34 1996
Definition: prex.h:225
@ PREX_MBOX_FROM_LAX_MATCH_ENVSENDER
From [god at heaven.af.mil] Sat Jan 3 01:05:34 1996
Definition: prex.h:222
@ PREX_MBOX_FROM_LAX_MATCH_TIME
From god@heaven.af.mil Sat Jan 10 [01:05:34] 1996
Definition: prex.h:229
@ PREX_MBOX_FROM_LAX_MATCH_DAY
From god@heaven.af.mil Sat Jan [ 3] 01:05:34 1996
Definition: prex.h:226
@ PREX_MBOX_FROM_LAX_MATCH_YEAR
From god@heaven.af.mil Sat Jan 10 01:05:34 [1996]
Definition: prex.h:235
@ PREX_MBOX_FROM_MATCH_DAY
From god@heaven.af.mil Sat Jan [ 3] 01:05:34 1996
Definition: prex.h:206
@ PREX_MBOX_FROM_MATCH_MONTH
From god@heaven.af.mil Sat [Jan] 3 01:05:34 1996
Definition: prex.h:205
@ PREX_MBOX_FROM_MATCH_YEAR
From god@heaven.af.mil Sat Jan 10 01:05:34 [1996]
Definition: prex.h:210
@ PREX_MBOX_FROM_MATCH_ENVSENDER
From [god@heaven.af.mil] Sat Jan 3 01:05:34 1996
Definition: prex.h:203
@ PREX_MBOX_FROM_MATCH_TIME
From god@heaven.af.mil Sat Jan 10 [01:05:34] 1996
Definition: prex.h:209
@ PREX_MBOX_FROM_LAX
[From god@heaven.af.mil Sat Jan 3 01:05:34 1996]
Definition: prex.h:41
@ PREX_MBOX_FROM
[From god@heaven.af.mil Sat Jan 3 01:05:34 1996]
Definition: prex.h:40
static size_t mutt_regmatch_len(const regmatch_t *match)
Return the length of a match.
Definition: regex3.h:80
static regoff_t mutt_regmatch_start(const regmatch_t *match)
Return the start of a match.
Definition: regex3.h:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function: