NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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?
 

Detailed Description

Determine who the email is from.

Authors
  • Richard Russon

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 49 of file from.c.

50{
51 bool lax = false;
52
53 const regmatch_t *match = mutt_prex_capture(PREX_MBOX_FROM, s);
54 if (!match)
55 {
57 if (!match)
58 {
59 mutt_debug(LL_DEBUG1, "Could not parse From line: <%s>\n", s);
60 return false;
61 }
62 lax = true;
63 mutt_debug(LL_DEBUG2, "Fallback regex for From line: <%s>\n", s);
64 }
65
66 if (path)
67 {
68 const regmatch_t *msender = &match[lax ? PREX_MBOX_FROM_LAX_MATCH_ENVSENDER : PREX_MBOX_FROM_MATCH_ENVSENDER];
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 mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
@ LL_DEBUG1
Log at debug level 1.
Definition: logging2.h:43
#define MIN(a, b)
Definition: memory.h:32
time_t mutt_date_make_time(struct tm *t, bool local)
Convert struct tm to time_t
Definition: date.c:242
int mutt_date_check_month(const char *s)
Is the string a valid month name.
Definition: date.c:432
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:581
regmatch_t * mutt_prex_capture(enum Prex which, const char *str)
Match a precompiled regex against a string.
Definition: prex.c:298
@ PREX_MBOX_FROM_LAX_MATCH_MONTH
From god@heaven.af.mil Sat [Jan] 3 01:05:34 1996
Definition: prex.h:203
@ PREX_MBOX_FROM_LAX_MATCH_ENVSENDER
From [god at heaven.af.mil] Sat Jan 3 01:05:34 1996
Definition: prex.h:200
@ PREX_MBOX_FROM_LAX_MATCH_TIME
From god@heaven.af.mil Sat Jan 10 [01:05:34] 1996
Definition: prex.h:207
@ PREX_MBOX_FROM_LAX_MATCH_DAY
From god@heaven.af.mil Sat Jan [ 3] 01:05:34 1996
Definition: prex.h:204
@ PREX_MBOX_FROM_LAX_MATCH_YEAR
From god@heaven.af.mil Sat Jan 10 01:05:34 [1996]
Definition: prex.h:213
@ PREX_MBOX_FROM_MATCH_DAY
From god@heaven.af.mil Sat Jan [ 3] 01:05:34 1996
Definition: prex.h:184
@ PREX_MBOX_FROM_MATCH_MONTH
From god@heaven.af.mil Sat [Jan] 3 01:05:34 1996
Definition: prex.h:183
@ PREX_MBOX_FROM_MATCH_YEAR
From god@heaven.af.mil Sat Jan 10 01:05:34 [1996]
Definition: prex.h:188
@ PREX_MBOX_FROM_MATCH_ENVSENDER
From [god@heaven.af.mil] Sat Jan 3 01:05:34 1996
Definition: prex.h:181
@ PREX_MBOX_FROM_MATCH_TIME
From god@heaven.af.mil Sat Jan 10 [01:05:34] 1996
Definition: prex.h:187
@ 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:77
static regoff_t mutt_regmatch_start(const regmatch_t *match)
Return the start of a match.
Definition: regex3.h:57
+ Here is the call graph for this function:
+ Here is the caller graph for this function: