NeoMutt  2018-07-16 +952-a2da0a
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  */
98  if (mutt_list_match(tag, &MailToAllow))
99  {
100  if (mutt_str_strcasecmp(tag, "body") == 0)
101  {
102  if (body)
103  mutt_str_replace(body, value);
104  }
105  else
106  {
107  char *scratch = NULL;
108  size_t taglen = mutt_str_strlen(tag);
109 
110  safe_asprintf(&scratch, "%s: %s", tag, value);
111  scratch[taglen] = 0; /* overwrite the colon as mutt_rfc822_parse_line expects */
112  value = mutt_str_skip_email_wsp(&scratch[taglen + 1]);
113  mutt_rfc822_parse_line(e, NULL, scratch, value, true, false, true);
114  FREE(&scratch);
115  }
116  }
117  }
118 
119  /* RFC2047 decode after the RFC822 parsing */
128  rfc2047_decode(&e->x_label);
129  rfc2047_decode(&e->subject);
130 
131  rc = 0;
132 
133 out:
134  FREE(&tmp);
135  return rc;
136 }
void rfc2047_decode(char **pd)
Decode any RFC2047-encoded header fields.
Definition: rfc2047.c:649
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:77
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:498
struct Address * to
Definition: envelope.h:36
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:663
struct Address * sender
Definition: envelope.h:39
struct Address * reply_to
Definition: envelope.h:40
struct Address * mail_followup_to
Definition: envelope.h:41
int url_pct_decode(char *s)
Decode a percent-encoded string.
Definition: url.c:101
struct Address * from
Definition: envelope.h:35
struct Address * bcc
Definition: envelope.h:38
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:768
void mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:460
void rfc2047_decode_addrlist(struct Address *a)
Decode any RFC2047 headers in an Address list.
Definition: rfc2047.c:768
char * subject
Definition: envelope.h:44
struct Address * return_path
Definition: envelope.h:34
char * mutt_str_strdup(const char *str)
Copy a string, safely.
Definition: string.c:384
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:625
#define FREE(x)
Definition: memory.h:46
char * x_label
Definition: envelope.h:50
struct Address * cc
Definition: envelope.h:37

+ Here is the call graph for this function:

+ Here is the caller graph for this function: