NeoMutt  2018-07-16 +1360-3df4a2
Teaching an old dog new tricks
DOXYGEN
mutt_url.c File Reference

Parse and identify different URL schemes. More...

#include "config.h"
#include <ctype.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include "mutt/mutt.h"
#include "email/lib.h"
#include "mutt.h"
#include "globals.h"
+ Include dependency graph for mutt_url.c:

Go to the source code of this file.

Functions

int url_parse_mailto (struct Envelope *e, char **body, const char *src)
 Parse a mailto:// url. More...
 

Detailed Description

Parse and identify different URL schemes.

Authors
  • Thomas Roessler

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 mutt_url.c.

Function Documentation

int url_parse_mailto ( struct Envelope e,
char **  body,
const char *  src 
)

Parse a mailto:// url.

Parameters
[in]eEnvelope to fill
[out]bodyBody to
[in]srcString to parse
Return values
0Success
-1Error

Definition at line 47 of file mutt_url.c.

48 {
49  char *p = NULL;
50  char *tag = NULL, *value = NULL;
51 
52  int rc = -1;
53 
54  char *t = strchr(src, ':');
55  if (!t)
56  return -1;
57 
58  /* copy string for safe use of strtok() */
59  char *tmp = mutt_str_strdup(t + 1);
60  if (!tmp)
61  return -1;
62 
63  char *headers = strchr(tmp, '?');
64  if (headers)
65  *headers++ = '\0';
66 
67  if (url_pct_decode(tmp) < 0)
68  goto out;
69 
70  e->to = mutt_addr_parse_list(e->to, tmp);
71 
72  tag = headers ? strtok_r(headers, "&", &p) : NULL;
73 
74  for (; tag; tag = strtok_r(NULL, "&", &p))
75  {
76  value = strchr(tag, '=');
77  if (value)
78  *value++ = '\0';
79  if (!value || !*value)
80  continue;
81 
82  if (url_pct_decode(tag) < 0)
83  goto out;
84  if (url_pct_decode(value) < 0)
85  goto out;
86 
87  /* Determine if this header field is on the allowed list. Since NeoMutt
88  * interprets some header fields specially (such as
89  * "Attach: ~/.gnupg/secring.gpg"), care must be taken to ensure that
90  * only safe fields are allowed.
91  *
92  * RFC2368, "4. Unsafe headers"
93  * The user agent interpreting a mailto URL SHOULD choose not to create
94  * a message if any of the headers are considered dangerous; it may also
95  * choose to create a message with only a subset of the headers given in
96  * the URL. */
97  if (mutt_list_match(tag, &MailToAllow))
98  {
99  if (mutt_str_strcasecmp(tag, "body") == 0)
100  {
101  if (body)
102  mutt_str_replace(body, value);
103  }
104  else
105  {
106  char *scratch = NULL;
107  size_t taglen = mutt_str_strlen(tag);
108 
109  safe_asprintf(&scratch, "%s: %s", tag, value);
110  scratch[taglen] = 0; /* overwrite the colon as mutt_rfc822_parse_line expects */
111  value = mutt_str_skip_email_wsp(&scratch[taglen + 1]);
112  mutt_rfc822_parse_line(e, NULL, scratch, value, true, false, true);
113  FREE(&scratch);
114  }
115  }
116  }
117 
118  /* RFC2047 decode after the RFC822 parsing */
120 
121  rc = 0;
122 
123 out:
124  FREE(&tmp);
125  return rc;
126 }
bool mutt_list_match(const char *s, struct ListHead *h)
Is the string in the list (see notes)
Definition: list.c:170
int safe_asprintf(char **, const char *,...)
Definition: safe_asprintf.c:76
int mutt_rfc822_parse_line(struct Envelope *env, struct Email *e, char *line, char *p, bool user_hdrs, bool weed, bool do_2047)
Parse an email header.
Definition: parse.c:536
struct Address * to
Definition: envelope.h:42
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:662
int url_pct_decode(char *s)
Decode a percent-encoded string.
Definition: url.c:101
struct Address * mutt_addr_parse_list(struct Address *top, const char *s)
Parse a list of email addresses.
Definition: address.c:465
char * mutt_str_skip_email_wsp(const char *s)
Skip over whitespace as defined by RFC5322.
Definition: string.c:767
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:459
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:383
void rfc2047_decode_envelope(struct Envelope *env)
Decode the fields of an Envelope.
Definition: rfc2047.c:786
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:624
#define FREE(x)
Definition: memory.h:40

+ Here is the call graph for this function:

+ Here is the caller graph for this function: