0

Is there a known standard technique to parse a mailto URL string into components using a C program? Or should I do it manually using C string library with my own logic?

mailto:someone@example.com?subject=This%20is%20the%20subject&cc=someone_else@example.com&body=This%20is%20the%20body

Is there a way to do it using regex APIs?

stefan
  • 10,215
  • 4
  • 49
  • 90
Bose
  • 381
  • 3
  • 16
  • 1
    since you mentionned c++ in your tags, Boost has a regex module which can be used to validate emails: http://www.codeobsessed.com/code/viewtopic.php?f=18&t=156 – lucasg Sep 30 '13 at 11:36
  • @georgesl c++11 has regex, no need for Boost, however using regex to validate email addresses comes with plenty of issues - see [this question](http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address) for more details. – msam Sep 30 '13 at 11:42
  • 1
    @msam not all compilers (g++, sigh) implement regex in a usable way. – stefan Sep 30 '13 at 11:44
  • I am looking for C implementation. Removed C++ from tag – Bose Sep 30 '13 at 11:44
  • [this](http://www.w3.org/Library/src/HTParse.c) might be at least partially useful if you don't find anything else – msam Sep 30 '13 at 11:47
  • Isn't this nice exercise how to use lexx & yacc? – alk Sep 30 '13 at 12:05

2 Answers2

0

First of all, C or C++? I assume you're working in C++. If so, take a look at this post.
It mentions a library called cpp-netlib, which contains a class named uri. It should suit your purposes.

Community
  • 1
  • 1
hauzer
  • 258
  • 3
  • 12
  • I am looking for C implementation. Removed C++ from tag – Bose Sep 30 '13 at 11:42
  • @Bose I'm confused. Do you need C or C++? – hauzer Sep 30 '13 at 11:43
  • @Bose Take a look at [uriparser](http://uriparser.sourceforge.net/). It claims to abide strictly by [RFC 3986](http://tools.ietf.org/html/rfc3986), which describes the `mailto:` URI scheme. – hauzer Sep 30 '13 at 11:52
0

You could use strstr to search for mailto: and take the characters you want.

Here's an example:

char *mailto = strstr( str, "mailto:" );

char *qm = strchr( mailto, '?' );

char *email = mailto + strlen("mailto:");

*qm = '\0';

You can take the other components using the same thing. The email should point to someone@example.com. This will modify the input string though.

George Chondrompilas
  • 3,167
  • 27
  • 35
  • This is how I am planning to do, but just was wondering if there are standard library APIs are available for the same purpose. – Bose Sep 30 '13 at 12:23