this is all in another branch, but... has to be tested here. So. fixes. peg-mime
authorKrista Grothoff <krista@pep-project.org>
Wed, 21 Sep 2016 22:15:18 +0200
branchpeg-mime
changeset 11839c5df64440d0
parent 1182 179d3ba1053d
child 1184 0c430ea338dc
this is all in another branch, but... has to be tested here. So. fixes.
mime-parser/Makefile
mime-parser/mailmime.leg
mime-parser/mailmime.peg
src/mailmime.c
src/mailmime.h
     1.1 --- a/mime-parser/Makefile	Wed Sep 21 01:17:10 2016 +0200
     1.2 +++ b/mime-parser/Makefile	Wed Sep 21 22:15:18 2016 +0200
     1.3 @@ -1,12 +1,12 @@
     1.4  include ../Makefile.conf
     1.5  
     1.6  all: generate
     1.7 -	cp mailmime.peg.c.src ../src/.
     1.8 +	cp mailmime.leg.c.src ../src/.
     1.9  
    1.10  generate: 
    1.11 -	peg mailmime.peg -o mailmime.peg.c.src
    1.12 +	leg mailmime.leg -o mailmime.leg.c.src
    1.13  
    1.14  .PHONY: clean
    1.15  
    1.16  clean:
    1.17 -	rm -f mailmime.peg.c
    1.18 +	rm -f mailmime.leg.c
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/mime-parser/mailmime.leg	Wed Sep 21 22:15:18 2016 +0200
     2.3 @@ -0,0 +1,435 @@
     2.4 +# TODO, DON'T FORGET - CHECK OWNERSHIP ON ALL ENGINE DS FUNCTIONS AND OMIT STRDUPS WHEN POSSIBLE
     2.5 +# CLEAN UP MEMORY ON FAILURE
     2.6 +# ERROR HANDLING AND RECOVERY
     2.7 +# ALL THE THINGS
     2.8 +#
     2.9 +%{
    2.10 +#define YYSTYPE void*
    2.11 +#include "../src/stringpair.h"
    2.12 +#include "../src/message.h"
    2.13 +%}
    2.14 +
    2.15 +Mail                    =      ( Header )+ CRLF ( Body )? EOF
    2.16 +
    2.17 +Header                  =     ( < MIMEHeader >  | 
    2.18 +                                < MessageHeader >  | 
    2.19 +                                < GenericHeader > )
    2.20 +
    2.21 +GenericHeader           =      HeaderKey COLON_PLUS_WS < HeaderText > 
    2.22 +                                    {
    2.23 +                                        stringpair_list_add(yy->parsed_msg->opt_fields, new_stringpair(yy->tmp_key, yytext));
    2.24 +                                        free(yy->tmp_key);
    2.25 +                                        yy->tmp_key = NULL;
    2.26 +                                    }
    2.27 +                                   ~{/* FAIL */
    2.28 +                                        if (yy->tmp_key)
    2.29 +                                            free(yy->tmp_key);
    2.30 +                                        yy->tmp_key = NULL;
    2.31 +                                    }
    2.32 +
    2.33 +HeaderKey               =      < ( Alpha | Digit | OrdinarySymbol )+ >
    2.34 +                                    {
    2.35 +                                        yy->tmp_key = strdup(yytext);
    2.36 +                                    }                        
    2.37 +HeaderPhrase            =      EncodedWord | Word
    2.38 +HeaderText              =      HeaderLine ( HeaderCont )* 
    2.39 +HeaderCont              =      Whitespace HeaderLine
    2.40 +HeaderLine              =      HeaderPhrase* CRLF
    2.41 +
    2.42 +#MIME Header Blocks
    2.43 +
    2.44 +# Mime-related headers
    2.45 +MIMEHeader              =      MIMEVersionHeader |
    2.46 +                               MIMEContentIDHeader |
    2.47 +                               MIMEContentTypeHeader |
    2.48 +                               MIMETransfEncodeHeader |
    2.49 +                               MIMEContentDescHeader |
    2.50 +                               MIMEExtensionHeader
    2.51 +
    2.52 +
    2.53 +# TODO NEXT: Translate headers so we get the parts etc into the right places.
    2.54 +MIMEExtensionHeader     =      MIMEContentDispoHeader | MIMEGenericExtHeader
    2.55 +MIMEVersionHeader       =      MIMEVersionKey COLON_PLUS_WS < VersionString >
    2.56 +                                    {
    2.57 +                                        stringpair_list_add(yy->parsed_msg->opt_fields, new_stringpair("MIME-Version", yytext));
    2.58 +                                    }
    2.59 +MIMEContentTypeHeader   =      MIMEContentTypeKey COLON_PLUS_WS ContentTypeString
    2.60 +MIMEContentIDHeader     =      MIMEContentIDKey COLON_PLUS_WS ContentIDString
    2.61 +MIMETransfEncodeHeader  =      MIMETransfEncodeKey COLON_PLUS_WS TransfEncodeString
    2.62 +MIMEContentDescHeader   =      MIMEContentDescKey COLON_PLUS_WS ContentDescString
    2.63 +
    2.64 +MIMEContentDispoHeader  =      MIMEContentDispoKey COLON_PLUS_WS ContentDispoString
    2.65 +MIMEGenericExtHeader    =      MIMEExtensionKey COLON_PLUS_WS ExtensionString
    2.66 +
    2.67 +MIMEVersionKey          =      'MIME-Version'
    2.68 +MIMEContentTypeKey      =      'Content-Type'
    2.69 +MIMEContentDispoKey     =      'Content-Disposition'
    2.70 +MIMETransfEncodeKey     =      'Content-Transfer-Encoding'
    2.71 +MIMEContentIDKey        =      'Content-ID'
    2.72 +MIMEContentDescKey      =      'Content-Description'
    2.73 +MIMEExtensionKey        =      'Content-'HeaderKey
    2.74 +
    2.75 +#VersionString           =     Text* Digit Text* "." Text* Digit Text* 
    2.76 +VersionString           =      HeaderText
    2.77 +ContentTypeString       =      ContentType "|" ContentSubtype (";" Parameter)*
    2.78 +ContentDispoString      =      ContentDisposition
    2.79 +TransfEncodeString      =      "7bit" | "8bit" | "binary" |
    2.80 +                                "quoted-printable" | "base64" |
    2.81 +                                XToken | IETFToken
    2.82 +ContentIDString         =      MsgID
    2.83 +ContentDescString       =      HeaderText
    2.84 +ExtensionString         =      HeaderText
    2.85 +
    2.86 +# RFC2045 Section 5 - we should extend these to ones we care about
    2.87 +ContentType             =      DiscreteContentType | CompositeContentType
    2.88 +DiscreteContentType     =      "text" | "image" | "audio" | 
    2.89 +                                "video" | "application" | 
    2.90 +                                ExtensionToken
    2.91 +CompositeContentType    =      "message" | "multipart" | 
    2.92 +                                ExtensionToken
    2.93 +ExtensionToken          =      XToken | IETFToken
    2.94 +XToken                  =      "X-" Token
    2.95 +IETFToken               =      Token
    2.96 +ContentSubtype          =      "mixed" | "digest" | "rfc822" | "alternative" | "related" |
    2.97 +                                "signed" | "encrypted" | "pgp-encrypted" | "pgp-keys" | "pgp-signature" 
    2.98 +                                | ExtensionToken | IANAToken
    2.99 +IANAToken               =      Token
   2.100 +
   2.101 +Parameter               =      RegularParameter | ExtendedParameter
   2.102 +RegularParameter        =      RegularParameterName "=" Value
   2.103 +RegularParameterName    =      Attribute Section?
   2.104 +Value                   =      Token | QuotedString
   2.105 +Token                   =      (![TSpecials ASCII_CTL Space] ASCII_CHAR)?
   2.106 +Attribute               =      AttributeChar+
   2.107 +AttributeChar           =      (![NonAttributeChar] ASCII_Printable)
   2.108 +NonAttributeChar        =      Space | "*" | "'" | "%" | TSpecials
   2.109 +Section                 =      InitialSection | OtherSections
   2.110 +InitialSection          =      "*0"
   2.111 +OtherSections           =      "*" ("1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9") Digit*
   2.112 +ExtendedParameter       =      (ExtendedInitialName "=" ExtendedInitialValue) |
   2.113 +                                (ExtendedOtherNames "="ExtendedOtherValues)
   2.114 +ExtendedInitialName     =      Attribute InitialSection? "*"
   2.115 +ExtendedOtherNames      =      Attribute OtherSections "*"
   2.116 +ExtendedInitialValue    =      [Charset] "'" [Language] "'" ExtendedOtherValues
   2.117 +ExtendedOtherValues     =      (ExtOctet | AttributeChar)*
   2.118 +ExtOctet                =      "%" HexDigit HexDigit
   2.119 +
   2.120 +
   2.121 +ContentDisposition      =      DispositionType *( ";" DispositionParm )
   2.122 +DispositionType         =      "inline" | "attachment" | DispExtType
   2.123 +DispExtType             =      Token
   2.124 +DispositionParm         =      FilenameParm | DispositionExtParm
   2.125 +FilenameParm            =      "filename" "=" Value | "filename*" "=" ExtValue
   2.126 +DispositionExtParm      =      Token "=" Value | ExtToken "=" ExtValue
   2.127 +ExtToken                =      Token "*"
   2.128 +ExtValue                =      Value
   2.129 +
   2.130 +# Message-related headers (per RFC2822)
   2.131 +MessageHeader           =     ( MessageIDHeader |
   2.132 +                                MessageToHeader |
   2.133 +                                MessageFromHeader |
   2.134 +                                MessageCCHeader |
   2.135 +                                MessageBCCHeader |
   2.136 +                                MessageSubjHeader |
   2.137 +                                MessageReplyToHeader |
   2.138 +                                MessageInReplyToHeader |
   2.139 +                                MessageRefsHeader ) CRLF      
   2.140 +                                
   2.141 +MessageIDHeader         =      MessageIDKey COLON_PLUS_WS IDString
   2.142 +MessageToHeader         =      MessageToKey COLON_PLUS_WS < ToString >  
   2.143 +MessageFromHeader       =      MessageFromKey COLON_PLUS_WS FromString
   2.144 +MessageCCHeader         =      MessageCCKey COLON_PLUS_WS CCString
   2.145 +MessageBCCHeader        =      MessageBCCKey COLON_PLUS_WS BCCString
   2.146 +MessageSubjHeader       =      MessageSubjKey COLON_PLUS_WS Whitespace* SubjString
   2.147 +MessageReplyToHeader    =      MessageReplyToKey COLON_PLUS_WS ReplyToString
   2.148 +MessageInReplyToHeader  =      MessageInReplyToKey COLON_PLUS_WS InReplyToString
   2.149 +MessageRefsHeader       =      MessageRefsKey COLON_PLUS_WS RefsString
   2.150 +MessageIDKey            =      'Message-ID'
   2.151 +MessageToKey            =      'To'
   2.152 +MessageFromKey          =      'From'
   2.153 +MessageCCKey            =      'Cc'
   2.154 +MessageBCCKey           =      'Bcc'
   2.155 +MessageSubjKey          =      'Subject'
   2.156 +MessageReplyToKey       =      'Reply-To'
   2.157 +MessageInReplyToKey     =      'In-Reply-To'
   2.158 +MessageRefsKey          =      'References'  
   2.159 +IDString                =      < MsgID > 
   2.160 +                                    {
   2.161 +                                        yy->parsed_msg->id = strdup(yytext);
   2.162 +                                    }
   2.163 +ToString                =      AddressList 
   2.164 +                                    {
   2.165 +                                        yy->parsed_msg->to = yy->curr_address_list;
   2.166 +                                        yy->curr_address_list = NULL;
   2.167 +                                    } 
   2.168 +                                   ~{/* FAIL */
   2.169 +                                        if (yy->curr_address_list)
   2.170 +                                            free_identity_list(yy->curr_address_list);
   2.171 +                                        yy->curr_address_list = NULL;
   2.172 +                                    }
   2.173 +                                                
   2.174 +FromString              =      MailboxList 
   2.175 +                                    {
   2.176 +                                        yy->parsed_msg->from = identity_dup(yy->curr_address_list->ident); 
   2.177 +                                        free_identity_list(yy->curr_address_list); 
   2.178 +                                        yy->curr_address_list->ident = NULL; 
   2.179 +                                    }
   2.180 +                                    ~{/* FAIL */
   2.181 +                                        if (yy->curr_address_list)
   2.182 +                                            free_identity_list(yy->curr_address_list);
   2.183 +                                        yy->curr_address_list = NULL;
   2.184 +                                    }
   2.185 +
   2.186 +CCString                =      AddressList {yy->parsed_msg->cc = yy->curr_address_list; 
   2.187 +                                            yy->curr_address_list = NULL;}
   2.188 +                                   ~{/* FAIL */
   2.189 +                                        if (yy->curr_address_list)
   2.190 +                                            free_identity_list(yy->curr_address_list);
   2.191 +                                        yy->curr_address_list = NULL;
   2.192 +                                    }
   2.193 +BCCString               =      AddressList 
   2.194 +                                    {
   2.195 +                                        yy->parsed_msg->bcc = yy->curr_address_list; 
   2.196 +                                        yy->curr_address_list = NULL;
   2.197 +                                    }
   2.198 +                                   ~{/* FAIL */
   2.199 +                                        if (yy->curr_address_list)
   2.200 +                                            free_identity_list(yy->curr_address_list);
   2.201 +                                        yy->curr_address_list = NULL;
   2.202 +                                    }
   2.203 +
   2.204 +SubjString              =      < HeaderText > 
   2.205 +                                    {
   2.206 +                                        yy->parsed_msg->shortmsg = strdup(yytext);
   2.207 +                                    }
   2.208 +ReplyToString           =      AddressList 
   2.209 +                                    {
   2.210 +                                        yy->parsed_msg->reply_to = yy->curr_address_list; 
   2.211 +                                        yy->curr_address_list = NULL;
   2.212 +                                    }
   2.213 +                                   ~{/* FAIL */
   2.214 +                                        if (yy->curr_address_list)
   2.215 +                                            free_identity_list(yy->curr_address_list);
   2.216 +                                        yy->curr_address_list = NULL;
   2.217 +                                    } 
   2.218 +InReplyToString         =      MsgID+ 
   2.219 +                                    {
   2.220 +                                        yy->parsed_msg->in_reply_to = yy->curr_msg_id_list; 
   2.221 +                                        yy->curr_msg_id_list = NULL;
   2.222 +                                    }
   2.223 +                                    ~{/* FAIL */
   2.224 +                                        if (yy->curr_msg_id_list)
   2.225 +                                            free_identity_list(yy->curr_msg_id_list);
   2.226 +                                        yy->curr_msg_id_list = NULL;
   2.227 +                                    }
   2.228 +
   2.229 +RefsString              =      MsgID+ 
   2.230 +                                    {
   2.231 +                                        yy->parsed_msg->references = yy->curr_msg_id_list; 
   2.232 +                                        yy->curr_msg_id_list = NULL;
   2.233 +                                    }
   2.234 +                                    ~{/* FAIL */
   2.235 +                                        if (yy->curr_msg_id_list)
   2.236 +                                            free_identity_list(yy->curr_msg_id_list);
   2.237 +                                        yy->curr_msg_id_list = NULL;
   2.238 +                                    }
   2.239 +
   2.240 +# RFC2822 Address Specification
   2.241 +Address                 =      Mailbox | Group 
   2.242 +Mailbox                 =      (mb:NameAddr | mb:AddrSpec) 
   2.243 +                                    { 
   2.244 +                                        if (!yy->curr_address_list)
   2.245 +                                            yy->curr_address_list = new_identity_list(mb); 
   2.246 +                                        else
   2.247 +                                            identity_list_add(yy->curr_address_list, mb); 
   2.248 +                                    }
   2.249 +# Split rule instead of using ? is because d comes back undefined when name empty otherwise
   2.250 +NameAddr                =      <a:AngleAddr> 
   2.251 +                                    { 
   2.252 +                                        $$ = (void*)new_identity(a, NULL, strdup(yytext), NULL); 
   2.253 +                                    } 
   2.254 +                                | <d:DisplayName a:AngleAddr> 
   2.255 +                                    { 
   2.256 +                                        $$ = (void*)new_identity(a, NULL, strdup(yytext), d); 
   2.257 +                                    }
   2.258 +AngleAddr               =      CFWS? "<" <AddrSpec> ">" CFWS? 
   2.259 +                                    {
   2.260 +                                        $$ = strdup(yytext);
   2.261 +                                    } 
   2.262 +                                | oaa:ObsAngleAddr 
   2.263 +                                    {
   2.264 +                                        $$ = strdup(oaa);
   2.265 +                                    }
   2.266 +# FIXME: Process group
   2.267 +Group                   =      DisplayName ":" (MailboxList | CFWS)? ";" CFWS?
   2.268 +DisplayName             =      < Phrase > {$$ = strdup(yytext);}
   2.269 +MailboxList             =      (Mailbox ("," Mailbox)*) | ObsMBoxList
   2.270 +AddressList             =      (Address ("," Address)*) | ObsAddrList 
   2.271 +
   2.272 +AddrSpec                =      LocalPart "@" Domain
   2.273 +LocalPart               =      DotAtom | QuotedString | ObsLocalPart
   2.274 +Domain                  =      DotAtom | DomainLiteral | ObsDomain
   2.275 +DomainLiteral           =      CFWS? "[" (FoldingWhiteSpace? DContent)* FoldingWhiteSpace? "]" CFWS?
   2.276 +DContent                =      DText | QuotedPair
   2.277 +DText                   =      NoWSCtl |
   2.278 +                                [\041-\132] |
   2.279 +                                [\136-\176]
   2.280 +
   2.281 +# Supported Obsolete Addressing
   2.282 +ObsAngleAddr            =      CFWS? "<" < ObsRoute? AddrSpec > ">" CFWS? {$$ = strdup(yytext);}
   2.283 +ObsRoute                =      CFWS? ObsDomainList ":" CFWS?
   2.284 +ObsDomainList           =      "@" Domain ((CFWS | "," )* CFWS? "@" Domain)*
   2.285 +ObsLocalPart            =      RFCWord ("." RFCWord)*
   2.286 +ObsDomain               =      Atom ("." Atom)*
   2.287 +ObsMBoxList             =      (Mailbox? CFWS? "," CFWS?)+ Mailbox?
   2.288 +ObsAddrList             =      (Address? CFWS? "," CFWS?)+ Address?
   2.289 +                      
   2.290 +                      
   2.291 +# RFC2822 Message ID - FIXME - what should this look like?
   2.292 +MsgID                   =       CFWS? "<" < IDLeft "@" IDRight > ">" CFWS? 
   2.293 +                                    { 
   2.294 +                                        if (!yy->curr_msg_id_list)
   2.295 +                                                yy->curr_msg_id_list = new_stringlist(strdup(yytext)); 
   2.296 +                                        else
   2.297 +                                                identity_list_add(yy->curr_msg_id_list, (strdup(yytext))); 
   2.298 +                                    }
   2.299 +IDLeft                  =       DotAtomText | NoFoldQuote | ObsIDLeft
   2.300 +IDRight                 =       DotAtomText | NoFoldLiteral | ObsIDRight
   2.301 +NoFoldQuote             =       "\"" *(QText | QuotedPair) "\""
   2.302 +NoFoldLiteral           =       "[" *(DText | QuotedPair) "]"
   2.303 +ObsIDLeft               =      LocalPart
   2.304 +ObsIDRight              =      Domain
   2.305 +                      
   2.306 +Body                    =      PlainBody
   2.307 +PlainBody               =      .* EOF
   2.308 +
   2.309 +Encapsulation       =      Delimiter BodyPart CRLF
   2.310 +CloseDelimiter      =      Delimiter "--"
   2.311 +Delimiter           =      CRLF DashBoundary
   2.312 +BodyPart            =      MIMEHeader+ (CRLF OCTET*)?
   2.313 +DashBoundary        =      "--" Boundary
   2.314 +Boundary            =      < BChars* BCharsNoSpace >
   2.315 +BCharsNoSpace       =      BChars | Space
   2.316 +BChars              =      Digit | Alpha | "'" | "(" | ")" |
   2.317 +                            "+" | "_" | "," | "-" | "." |
   2.318 +                            "/" | ":" | "=" | "?"
   2.319 +Preamble            =      DiscardText
   2.320 +Epilogue            =      DiscardText
   2.321 +DiscardText         =      ((!CRLF)* CRLF)* (!CRLF)*
   2.322 +
   2.323 +CContent            =      CText | QuotedPair | Comment
   2.324 +CFWS                =      (FoldingWhiteSpace? Comment)* ((FoldingWhiteSpace? Comment) | FoldingWhiteSpace)
   2.325 +Comment             =      "(" ([FoldingWhiteSpace]? CContent)* FoldingWhiteSpace? ")"
   2.326 +FoldingWhiteSpace   =      (Whitespace* CRLF)? Whitespace+ |   
   2.327 +                            Whitespace+ (CRLF Whitespace+)*
   2.328 +CText               =      NoWSCtl | 
   2.329 +                            Alpha | Digit | CommentSymbols
   2.330 +QuotedString        =      CFWS '"' (FoldingWhiteSpace? QuotedContent)* FoldingWhiteSpace? '"'
   2.331 +QuotedContent       =      QText | QuotedPair
   2.332 +QText               =      !["\"" "\\" CR]
   2.333 +QuotedPair          =      "\\". | "\\" Text
   2.334 +
   2.335 +Text                =      ( Word | Space )+
   2.336 +Word                =      ( AlphaNum | Symbol )+
   2.337 +AlphaNum            =      Alpha | Digit
   2.338 +Alpha               =      [a-zA-Z]
   2.339 +Digit               =      [0-9]
   2.340 +Symbol              =      OrdinarySymbol | COLON_PLUS_WS
   2.341 +Whitespace          =      Space+
   2.342 +Space               =      [' ' '\t']
   2.343 +
   2.344 +OrdinarySymbol      =      ["!" "#" "$" "%" "&" "'" "*" "+" "\-" "/" "=" "?" "^" "_" "`" "{" "|" "}" "~" "\[" "\]" "@" ";" "." "<" ">" "\"" "(" ")" "," "\\"]
   2.345 +CommentSymbols      =      [\041-\047] | [\52-57] | [\072-\100] | [\133] | [\135-\140] | [\173-177]
   2.346 +
   2.347 +TSpecials           =      !["."] (Specials | ["/" "?" "="])
   2.348 +Specials            =      ["(" ")" "<" ">" "@" "," ";" ":" "\\" "\"" "." "\[" "\]"]
   2.349 +
   2.350 +ASCII_CHAR          =      [\000-\127]
   2.351 +ASCII_Printable     =      [\041-\176]
   2.352 +ASCII_CTL           =      [\000-\031] | [\127]
   2.353 +LWS                 =      CRLF? Space+
   2.354 +
   2.355 +
   2.356 +
   2.357 +OCTET               =      '\\' (([0-1] [0-9] [0-9]) | ("2" (([0-4] [0-9]) | ("5" [0-5])))) 
   2.358 +COLON               =      ':'
   2.359 +NEWLINE             =      '\n'
   2.360 +CR                  =      '\r'
   2.361 +CRLF                =      CR CR? NEWLINE 
   2.362 +EOF                 =      !.
   2.363 +NoWSCtl             =      [\001-\010] | [\013-\014] | [\016-\037] | [\177]
   2.364 +
   2.365 +
   2.366 +HexDigit                =      (Digit | "A" | "B" | "C" | "D" | "E" | "F")
   2.367 +
   2.368 +EncodedWord             =      <"=?" Charset ("*" Language)? "?" EncodedText "?="> |
   2.369 +                                <"=?" Charset "?" Encoding "?" EncodedText "?=">
   2.370 +                                
   2.371 +Encoding                =      [Q q] | [B b]
   2.372 +
   2.373 +Charset                 =      "utf-8" |
   2.374 +                                "US-ASCII" |
   2.375 +                                "Big5" |
   2.376 +                                "EUC-JP" |
   2.377 +                                "EUC-KR" |
   2.378 +                                "GB2312" |
   2.379 +                                "ISO-2022-JP" |
   2.380 +                                "ISO-2022-JP-2" |
   2.381 +                                "ISO-2022-KR" |
   2.382 +                                "ISO-8859-1" |
   2.383 +                                "ISO-8859-10" |
   2.384 +                                "ISO-8859-2" |
   2.385 +                                "ISO-8859-3" |
   2.386 +                                "ISO-8859-4" |
   2.387 +                                "ISO-8859-5" |
   2.388 +                                "ISO-8859-6" |
   2.389 +                                "ISO-8859-6-E" |
   2.390 +                                "ISO-8859-6-I" |
   2.391 +                                "ISO-8859-7" |
   2.392 +                                "ISO-8859-8" |
   2.393 +                                "ISO-8859-8-E" |
   2.394 +                                "ISO-8859-8-I" |
   2.395 +                                "ISO-8859-9" |
   2.396 +                                "KOI8-R" |
   2.397 +                                "Shift_JIS"
   2.398 +
   2.399 +Language                =      PrimarySubtag ("-" Subtag)*
   2.400 +EncodedText             =      (!["?"] ( Alpha | Digit | Symbol ))+
   2.401 +PrimarySubtag           =      Alpha Alpha? Alpha? Alpha? Alpha? Alpha? Alpha? Alpha?
   2.402 +Subtag                  =      AlphaNum AlphaNum? AlphaNum? AlphaNum? AlphaNum? AlphaNum? AlphaNum? AlphaNum?
   2.403 +                            
   2.404 +# May need to be updated - this is ancient
   2.405 +UTF8Octets          =      UTF8Char*
   2.406 +UTF8Char            =      UTF8_1 | UTF8_2 | UTF8_3 | UTF8_4
   2.407 +UTF8_1              =      [\000-\177]
   2.408 +UTF8_2              =      [\302-\337] UTF8Tail
   2.409 +UTF8_3              =      [\340] [\240-\277] UTF8Tail | 
   2.410 +                            [\341-\354] UTF8Tail UTF8Tail |
   2.411 +                            [\355] [\200-\237] UTF8Tail | 
   2.412 +                            [\356-\357] UTF8Tail UTF8Tail
   2.413 +UTF8_4              =      [\360] [\220-\277] UTF8Tail UTF8Tail | [\361-\363] UTF8Tail UTF8Tail UTF8Tail |
   2.414 +                            [\364] [\200-\217] UTF8Tail UTF8Tail
   2.415 +UTF8Tail            =      [\200-\277]
   2.416 +
   2.417 +RFCWord             =      Atom | QuotedString
   2.418 +Phrase              =      RFCWord+ | ObsPhrase
   2.419 +ObsPhrase           =      RFCWord (RFCWord | "." | CFWS)*
   2.420 +
   2.421 +
   2.422 +# Atom (2822 - mostly for supported obsolete stuff)
   2.423 +AText               =      Alpha | Digit | 
   2.424 +                            "!" | "#" |   
   2.425 +                            "$" | "%" |   
   2.426 +                            "&" | "'" |
   2.427 +                            "*" | "+" |
   2.428 +                            "-" | "/" |
   2.429 +                            "=" | "?" |
   2.430 +                            "^" | "_" |
   2.431 +                            "`" | "{" |
   2.432 +                            "|" | "}" |
   2.433 +                            "~"
   2.434 +Atom                =       CFWS? AText+ CFWS?
   2.435 +DotAtom             =       CFWS? DotAtomText CFWS?
   2.436 +DotAtomText         =       AText+ ("." AText+)*
   2.437 +
   2.438 +COLON_PLUS_WS       =       Whitespace* COLON Whitespace*
     3.1 --- a/mime-parser/mailmime.peg	Wed Sep 21 01:17:10 2016 +0200
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,324 +0,0 @@
     3.4 -Mail                    <-      ( Header )+ CRLF ( Body )? EOF
     3.5 -
     3.6 -Header                  <-     ( < MIMEHeader > { printf("MIMEHeader! %s\n", yytext); } / 
     3.7 -                                < MessageHeader > { printf("MessageHeader!%s\n", yytext); } / 
     3.8 -                                < GenericHeader > { printf("GenericHeader!%s\n", yytext); } )
     3.9 -
    3.10 -GenericHeader           <-      HeaderKey COLON HeaderText
    3.11 -HeaderKey               <-      ( Alpha / Digit / OrdinarySymbol )+
    3.12 -HeaderPhrase            <-      EncodedWord / Word
    3.13 -HeaderText              <-      HeaderLine ( HeaderCont )*
    3.14 -HeaderCont              <-      Whitespace HeaderLine
    3.15 -HeaderLine              <-      HeaderPhrase* CRLF
    3.16 -
    3.17 -#MIME Header Blocks
    3.18 -
    3.19 -# MessageHeaders      <-      (EntityHeaderBlock Fields MIMEVersionHeader) /
    3.20 -#                             (EntityHeaderBlock MIMEVersionHeader Fields) /
    3.21 -#                             (MIMEVersionHeader Fields EntityHeaderBlock) /
    3.22 -#                             (MIMEVersionHeader EntityHeaderBlock Fields) /
    3.23 -#                             (Fields EntityHeaderBlock MIMEVersionHeader) /
    3.24 -#                             (Fields MIMEVersionHeader EntityHeaderBlock)
    3.25 -
    3.26 -# Horrible def.
    3.27 -# MessagePartHeaders         <-      Field* EntityHeaderBlock Field* 
    3.28 -
    3.29 -#MIMEMessageHeaderBlock  <-      EntityHeaderBlock   
    3.30 -#                                (Field* EntityHeaderBlock)
    3.31 -
    3.32 -# Not really clear if this ordering matters. Sigh.
    3.33 -#EntityHeaderBlock       <-      MIMEContentTypeHeader? MIMETransfEncodeHeader? MIMEContentIDHeader? MIMEContentDescHeader? MIMEExtensionHeader* 
    3.34 -
    3.35 -#Fields                  <-      MessageHeader / GenericHeader
    3.36 -
    3.37 -# Mime-related headers
    3.38 -MIMEHeader              <-      MIMEVersionHeader /
    3.39 -                                MIMEContentIDHeader /
    3.40 -                                MIMEContentTypeHeader /
    3.41 -                                MIMETransfEncodeHeader /
    3.42 -                                MIMEContentDescHeader /
    3.43 -                                MIMEExtensionHeader
    3.44 -
    3.45 -
    3.46 -MIMEExtensionHeader     <-      MIMEContentDispoHeader / MIMEGenericExtHeader
    3.47 -MIMEVersionHeader       <-      MIMEVersionKey COLON VersionString
    3.48 -MIMEContentTypeHeader   <-      MIMEContentTypeKey COLON ContentTypeString
    3.49 -MIMEContentIDHeader     <-      MIMEContentIDKey COLON ContentIDString
    3.50 -MIMETransfEncodeHeader  <-      MIMETransfEncodeKey COLON TransfEncodeString
    3.51 -MIMEContentDescHeader   <-      MIMEContentDescKey COLON ContentDescString
    3.52 -
    3.53 -MIMEContentDispoHeader  <-      MIMEContentDispoKey COLON ContentDispoString
    3.54 -MIMEGenericExtHeader    <-      MIMEExtensionKey COLON ExtensionString
    3.55 -
    3.56 -MIMEVersionKey          <-      'MIME-Version'
    3.57 -MIMEContentTypeKey      <-      'Content-Type'
    3.58 -MIMEContentDispoKey     <-      'Content-Disposition'
    3.59 -MIMETransfEncodeKey     <-      'Content-Transfer-Encoding'
    3.60 -MIMEContentIDKey        <-      'Content-ID'
    3.61 -MIMEContentDescKey      <-      'Content-Description'
    3.62 -MIMEExtensionKey        <-      'Content-'HeaderKey
    3.63 -
    3.64 -#VersionString           <-     Text* Digit Text* "." Text* Digit Text* 
    3.65 -VersionString           <-      HeaderText
    3.66 -ContentTypeString       <-      ContentType "/" ContentSubtype (";" Parameter)*
    3.67 -ContentDispoString      <-      ContentDisposition
    3.68 -TransfEncodeString      <-      "7bit" / "8bit" / "binary" /
    3.69 -                                "quoted-printable" / "base64" /
    3.70 -                                XToken / IETFToken
    3.71 -ContentIDString         <-      MsgID
    3.72 -ContentDescString       <-      HeaderText
    3.73 -ExtensionString         <-      HeaderText
    3.74 -
    3.75 -# RFC2045 Section 5 - we should extend these to ones we care about
    3.76 -ContentType             <-      DiscreteContentType / CompositeContentType
    3.77 -DiscreteContentType     <-      "text" / "image" / "audio" / 
    3.78 -                                "video" / "application" / 
    3.79 -                                ExtensionToken
    3.80 -CompositeContentType    <-      "message" / "multipart" / 
    3.81 -                                ExtensionToken
    3.82 -ExtensionToken          <-      XToken / IETFToken
    3.83 -XToken                  <-      "X-" Token
    3.84 -IETFToken               <-      Token
    3.85 -ContentSubtype          <-      "mixed" / "digest" / "rfc822" / "alternative" / "related" /
    3.86 -                                "signed" / "encrypted" / "pgp-encrypted" / "pgp-keys" / "pgp-signature" 
    3.87 -                                / ExtensionToken / IANAToken
    3.88 -IANAToken               <-      Token
    3.89 -
    3.90 -Parameter               <-      RegularParameter / ExtendedParameter
    3.91 -RegularParameter        <-      RegularParameterName "=" Value
    3.92 -RegularParameterName    <-      Attribute Section?
    3.93 -Value                   <-      Token / QuotedString
    3.94 -Token                   <-      (![TSpecials ASCII_CTL Space] ASCII_CHAR)?
    3.95 -Attribute               <-      AttributeChar+
    3.96 -AttributeChar           <-      (![NonAttributeChar] ASCII_Printable)
    3.97 -NonAttributeChar        <-      Space / "*" / "'" / "%" / TSpecials
    3.98 -Section                 <-      InitialSection / OtherSections
    3.99 -InitialSection          <-      "*0"
   3.100 -OtherSections           <-      "*" ("1" / "2" / "3" / "4" / "5" / "6" / "7" / "8" / "9") Digit*
   3.101 -ExtendedParameter       <-      (ExtendedInitialName "=" ExtendedInitialValue) /
   3.102 -                                (ExtendedOtherNames "="ExtendedOtherValues)
   3.103 -ExtendedInitialName     <-      Attribute InitialSection? "*"
   3.104 -ExtendedOtherNames      <-      Attribute OtherSections "*"
   3.105 -ExtendedInitialValue    <-      [Charset] "'" [Language] "'" ExtendedOtherValues
   3.106 -ExtendedOtherValues     <-      (ExtOctet / AttributeChar)*
   3.107 -ExtOctet                <-      "%" HexDigit HexDigit
   3.108 -
   3.109 -
   3.110 -ContentDisposition      <-      DispositionType *( ";" DispositionParm )
   3.111 -DispositionType         <-      "inline" / "attachment" / DispExtType
   3.112 -DispExtType             <-      Token
   3.113 -DispositionParm         <-      FilenameParm / DispositionExtParm
   3.114 -FilenameParm            <-      "filename" "=" Value / "filename*" "=" ExtValue
   3.115 -DispositionExtParm      <-      Token "=" Value / ExtToken "=" ExtValue
   3.116 -ExtToken                <-      Token "*"
   3.117 -ExtValue                <-      Value
   3.118 -
   3.119 -# Message-related headers (per RFC2822)
   3.120 -MessageHeader           <-     ( MessageIDHeader /
   3.121 -                                MessageToHeader /
   3.122 -                                MessageFromHeader /
   3.123 -                                MessageCCHeader /
   3.124 -                                MessageBCCHeader /
   3.125 -                                MessageSubjHeader /
   3.126 -                                MessageReplyToHeader /
   3.127 -                                MessageInReplyToHeader /
   3.128 -                                MessageRefsHeader ) CRLF      
   3.129 -                                
   3.130 -MessageIDHeader         <-      MessageIDKey COLON IDString
   3.131 -MessageToHeader         <-      MessageToKey COLON < ToString >     { printf("YO!!!\n"); printf("To: %s\n", yytext); }
   3.132 -MessageFromHeader       <-      MessageFromKey COLON FromString
   3.133 -MessageCCHeader         <-      MessageCCKey COLON CCString
   3.134 -MessageBCCHeader        <-      MessageBCCKey COLON BCCString
   3.135 -MessageSubjHeader       <-      MessageSubjKey COLON Whitespace* SubjString
   3.136 -MessageReplyToHeader    <-      MessageReplyToKey COLON ReplyToString
   3.137 -MessageInReplyToHeader  <-      MessageInReplyToKey COLON InReplyToString
   3.138 -MessageRefsHeader       <-      MessageRefsKey COLON RefsString
   3.139 -MessageIDKey            <-      'Message-ID'
   3.140 -MessageToKey            <-      'To'
   3.141 -MessageFromKey          <-      'From'
   3.142 -MessageCCKey            <-      'Cc'
   3.143 -MessageBCCKey           <-      'Bcc'
   3.144 -MessageSubjKey          <-      'Subject'
   3.145 -MessageReplyToKey       <-      'Reply-To'
   3.146 -MessageInReplyToKey     <-      'In-Reply-To'
   3.147 -MessageRefsKey          <-      'References'  
   3.148 -IDString                <-      MsgID CRLF
   3.149 -ToString                <-      AddressList { printf("YO1!!!\n"); }
   3.150 -FromString              <-      MailboxList
   3.151 -CCString                <-      AddressList
   3.152 -BCCString               <-      AddressList
   3.153 -SubjString              <-      < HeaderText > { printf("*** Subject: %s\n", yytext); }
   3.154 -ReplyToString           <-      AddressList
   3.155 -InReplyToString         <-      MsgID+
   3.156 -RefsString              <-      MsgID+
   3.157 -
   3.158 -
   3.159 -# RFC2822 Address Specification
   3.160 -Address                 <-      Mailbox / Group
   3.161 -Mailbox                 <-      (NameAddr / AddrSpec) { printf("YO2!!!\n"); }
   3.162 -NameAddr                <-      DisplayName? AngleAddr
   3.163 -AngleAddr               <-      CFWS? "<" AddrSpec ">" CFWS? / ObsAngleAddr
   3.164 -Group                   <-      DisplayName ":" (MailboxList / CFWS)? ";" CFWS?
   3.165 -DisplayName             <-      Phrase 
   3.166 -MailboxList             <-      (Mailbox ("," Mailbox)*) / ObsMBoxList
   3.167 -AddressList             <-      (Address ("," Address)*) / ObsAddrList
   3.168 -
   3.169 -AddrSpec                <-      LocalPart "@" Domain
   3.170 -LocalPart               <-      DotAtom / QuotedString / ObsLocalPart
   3.171 -Domain                  <-      DotAtom / DomainLiteral / ObsDomain
   3.172 -DomainLiteral           <-      CFWS? "[" (FoldingWhiteSpace? DContent)* FoldingWhiteSpace? "]" CFWS?
   3.173 -DContent                <-      DText / QuotedPair
   3.174 -DText                   <-      NoWSCtl /
   3.175 -                                [\041-\132] /
   3.176 -                                [\136-\176]
   3.177 -
   3.178 -# Supported Obsolete Addressing
   3.179 -ObsAngleAddr            <-      CFWS? "<" ObsRoute? AddrSpec ">" CFWS?
   3.180 -ObsRoute                <-      CFWS? ObsDomainList ":" CFWS?
   3.181 -ObsDomainList           <-      "@" Domain ((CFWS / "," )* CFWS? "@" Domain)*
   3.182 -ObsLocalPart            <-      RFCWord ("." RFCWord)*
   3.183 -ObsDomain               <-      Atom ("." Atom)*
   3.184 -ObsMBoxList             <-      (Mailbox? CFWS? "," CFWS?)+ Mailbox?
   3.185 -ObsAddrList             <-      (Address? CFWS? "," CFWS?)+ Address?
   3.186 -                      
   3.187 -                      
   3.188 -# RFC2822 Message ID
   3.189 -MsgID                   <-       CFWS? "<" IDLeft "@" IDRight ">" CFWS?
   3.190 -IDLeft                  <-       DotAtomText / NoFoldQuote / ObsIDLeft
   3.191 -IDRight                 <-       DotAtomText / NoFoldLiteral / ObsIDRight
   3.192 -NoFoldQuote             <-       "\"" *(QText / QuotedPair) "\""
   3.193 -NoFoldLiteral           <-       "[" *(DText / QuotedPair) "]"
   3.194 -ObsIDLeft               <-      LocalPart
   3.195 -ObsIDRight              <-      Domain
   3.196 -                      
   3.197 -Body                    <-      PlainBody
   3.198 -PlainBody               <-      .* EOF
   3.199 -
   3.200 -Encapsulation       <-      Delimiter BodyPart CRLF
   3.201 -CloseDelimiter      <-      Delimiter "--"
   3.202 -Delimiter           <-      CRLF DashBoundary
   3.203 -BodyPart            <-      MIMEHeader+ (CRLF OCTET*)?
   3.204 -DashBoundary        <-      "--" Boundary
   3.205 -Boundary            <-      < BChars* BCharsNoSpace >
   3.206 -BCharsNoSpace       <-      BChars / Space
   3.207 -BChars              <-      Digit / Alpha / "'" / "(" / ")" /
   3.208 -                            "+" / "_" / "," / "-" / "." /
   3.209 -                            "/" / ":" / "=" / "?"
   3.210 -Preamble            <-      DiscardText
   3.211 -Epilogue            <-      DiscardText
   3.212 -DiscardText         <-      ((!CRLF)* CRLF)* (!CRLF)*
   3.213 -
   3.214 -CContent            <-      CText / QuotedPair / Comment
   3.215 -CFWS                <-      (FoldingWhiteSpace? Comment)* ((FoldingWhiteSpace? Comment) / FoldingWhiteSpace)
   3.216 -Comment             <-      "(" ([FoldingWhiteSpace]? CContent)* FoldingWhiteSpace? ")"
   3.217 -FoldingWhiteSpace   <-      (Whitespace* CRLF)? Whitespace+ /   
   3.218 -                            Whitespace+ (CRLF Whitespace+)*
   3.219 -CText               <-      NoWSCtl / 
   3.220 -                            Alpha / Digit / CommentSymbols
   3.221 -QuotedString        <-      CFWS '"' (FoldingWhiteSpace? QuotedContent)* FoldingWhiteSpace? '"'
   3.222 -QuotedContent       <-      QText / QuotedPair
   3.223 -QText               <-      !["\"" "\\" CR]
   3.224 -QuotedPair          <-      "\\". / "\\" Text
   3.225 -
   3.226 -Text                <-      ( Word / Space )+
   3.227 -Word                <-      ( AlphaNum / Symbol )+
   3.228 -AlphaNum            <-      Alpha / Digit
   3.229 -Alpha               <-      [a-zA-Z]
   3.230 -Digit               <-      [0-9]
   3.231 -Symbol              <-      OrdinarySymbol / COLON
   3.232 -Whitespace          <-      Space+
   3.233 -Space               <-      [' ' '\t']
   3.234 -
   3.235 -OrdinarySymbol      <-      ["!" "#" "$" "%" "&" "'" "*" "+" "\-" "/" "=" "?" "^" "_" "`" "{" "|" "}" "~" "\[" "\]" "@" ";" "." "<" ">" "\"" "(" ")" "," "\\"]
   3.236 -CommentSymbols      <-      [\041-\047] / [\52-57] / [\072-\100] / [\133] / [\135-\140] / [\173-177]
   3.237 -
   3.238 -TSpecials           <-      !["."] (Specials / ["/" "?" "="])
   3.239 -Specials            <-      ["(" ")" "<" ">" "@" "," ";" ":" "\\" "\"" "." "\[" "\]"]
   3.240 -
   3.241 -ASCII_CHAR          <-      [\000-\127]
   3.242 -ASCII_Printable     <-      [\041-\176]
   3.243 -ASCII_CTL           <-      [\000-\031] / [\127]
   3.244 -LWS                 <-      CRLF? Space+
   3.245 -
   3.246 -
   3.247 -
   3.248 -OCTET               <-      '\\' (([0-1] [0-9] [0-9]) / ("2" (([0-4] [0-9]) / ("5" [0-5])))) 
   3.249 -COLON               <-      ':'
   3.250 -NEWLINE             <-      '\n'
   3.251 -CR                  <-      '\r'
   3.252 -CRLF                <-      CR CR? NEWLINE 
   3.253 -EOF                 <-      !.
   3.254 -NoWSCtl             <-      [\001-\010] / [\013-\014] / [\016-\037] / [\177]
   3.255 -
   3.256 -
   3.257 -HexDigit                <-      (Digit / "A" / "B" / "C" / "D" / "E" / "F")
   3.258 -
   3.259 -EncodedWord             <-      <"=?" Charset ("*" Language)? "?" EncodedText "?="> { printf("V1%s\n", yytext); } /
   3.260 -                                <"=?" Charset "?" Encoding "?" EncodedText "?="> { printf("V2%s\n", yytext); }
   3.261 -                                
   3.262 -Encoding                <-      [Q q] / [B b]
   3.263 -
   3.264 -Charset                 <-      "utf-8" /
   3.265 -                                "US-ASCII" /
   3.266 -                                "Big5" /
   3.267 -                                "EUC-JP" /
   3.268 -                                "EUC-KR" /
   3.269 -                                "GB2312" /
   3.270 -                                "ISO-2022-JP" /
   3.271 -                                "ISO-2022-JP-2" /
   3.272 -                                "ISO-2022-KR" /
   3.273 -                                "ISO-8859-1" /
   3.274 -                                "ISO-8859-10" /
   3.275 -                                "ISO-8859-2" /
   3.276 -                                "ISO-8859-3" /
   3.277 -                                "ISO-8859-4" /
   3.278 -                                "ISO-8859-5" /
   3.279 -                                "ISO-8859-6" /
   3.280 -                                "ISO-8859-6-E" /
   3.281 -                                "ISO-8859-6-I" /
   3.282 -                                "ISO-8859-7" /
   3.283 -                                "ISO-8859-8" /
   3.284 -                                "ISO-8859-8-E" /
   3.285 -                                "ISO-8859-8-I" /
   3.286 -                                "ISO-8859-9" /
   3.287 -                                "KOI8-R" /
   3.288 -                                "Shift_JIS"
   3.289 -
   3.290 -Language                <-      PrimarySubtag ("-" Subtag)*
   3.291 -EncodedText             <-      (!["?"] ( Alpha / Digit / Symbol ))+
   3.292 -PrimarySubtag           <-      Alpha Alpha? Alpha? Alpha? Alpha? Alpha? Alpha? Alpha?
   3.293 -Subtag                  <-      AlphaNum AlphaNum? AlphaNum? AlphaNum? AlphaNum? AlphaNum? AlphaNum? AlphaNum?
   3.294 -                            
   3.295 -# May need to be updated - this is ancient
   3.296 -UTF8Octets          <-      UTF8Char*
   3.297 -UTF8Char            <-      UTF8_1 / UTF8_2 / UTF8_3 / UTF8_4
   3.298 -UTF8_1              <-      [\000-\177]
   3.299 -UTF8_2              <-      [\302-\337] UTF8Tail
   3.300 -UTF8_3              <-      [\340] [\240-\277] UTF8Tail / 
   3.301 -                            [\341-\354] UTF8Tail UTF8Tail /
   3.302 -                            [\355] [\200-\237] UTF8Tail / 
   3.303 -                            [\356-\357] UTF8Tail UTF8Tail
   3.304 -UTF8_4              <-      [\360] [\220-\277] UTF8Tail UTF8Tail / [\361-\363] UTF8Tail UTF8Tail UTF8Tail /
   3.305 -                            [\364] [\200-\217] UTF8Tail UTF8Tail
   3.306 -UTF8Tail            <-      [\200-\277]
   3.307 -
   3.308 -RFCWord             <-      Atom / QuotedString
   3.309 -Phrase              <-      RFCWord+ / ObsPhrase
   3.310 -ObsPhrase           <-      RFCWord (RFCWord / "." / CFWS)*
   3.311 -
   3.312 -
   3.313 -# Atom (2822 - mostly for supported obsolete stuff)
   3.314 -AText               <-      Alpha / Digit / 
   3.315 -                            "!" / "#" /   
   3.316 -                            "$" / "%" /   
   3.317 -                            "&" / "'" /
   3.318 -                            "*" / "+" /
   3.319 -                            "-" / "/" /
   3.320 -                            "=" / "?" /
   3.321 -                            "^" / "_" /
   3.322 -                            "`" / "{" /
   3.323 -                            "|" / "}" /
   3.324 -                            "~"
   3.325 -Atom                <-       CFWS? AText+ CFWS?
   3.326 -DotAtom             <-       CFWS? DotAtomText CFWS?
   3.327 -DotAtomText         <-       AText+ ("." AText+)*
     4.1 --- a/src/mailmime.c	Wed Sep 21 01:17:10 2016 +0200
     4.2 +++ b/src/mailmime.c	Wed Sep 21 22:15:18 2016 +0200
     4.3 @@ -2,7 +2,7 @@
     4.4  #include <stdlib.h>
     4.5  #include <assert.h>
     4.6  #include "mailmime.h"
     4.7 -#include "mailmime.peg.c.src"
     4.8 +#include "mailmime.leg.c.src"
     4.9  #include "pEpEngine.h"
    4.10  
    4.11  DYNAMIC_API PEP_STATUS parse_mailmessage(const char *mimetext,
    4.12 @@ -24,9 +24,15 @@
    4.13      memset(&ctx, 0, sizeof(yycontext));
    4.14      ctx.input_str = mimetext;
    4.15      ctx.index_consumed = 0;
    4.16 -    ctx.parsed_msg = &_msg;
    4.17 +    ctx.parsed_msg = new_message(PEP_dir_incoming);
    4.18 +    ctx.curr_address_list = NULL;
    4.19 +    ctx.curr_msg_id_list = NULL;
    4.20 +    ctx.tmp_key = NULL;
    4.21 +    ctx.tmp_value = NULL;
    4.22      yyparse(&ctx);
    4.23  
    4.24 +    *msg = ctx.parsed_msg;
    4.25 +    
    4.26      return PEP_STATUS_OK;
    4.27  }
    4.28  
     5.1 --- a/src/mailmime.h	Wed Sep 21 01:17:10 2016 +0200
     5.2 +++ b/src/mailmime.h	Wed Sep 21 22:15:18 2016 +0200
     5.3 @@ -15,7 +15,11 @@
     5.4  #define YY_CTX_MEMBERS const char* input_str;    \
     5.5                         size_t index_consumed;    \
     5.6                         message* parsed_msg;     \
     5.7 -                       pEp_mailmime* msg_root;   
     5.8 +                       identity_list* curr_address_list; \
     5.9 +                       stringlist_t* curr_msg_id_list; \
    5.10 +                       pEp_mailmime* msg_root;      \
    5.11 +                       char* tmp_key;           \
    5.12 +                       char* tmp_value;
    5.13  
    5.14  #define YY_INPUT(yycontext, buf, result, max_size)                        \
    5.15  {                                                                         \
    5.16 @@ -85,6 +89,15 @@
    5.17  DYNAMIC_API PEP_STATUS parse_mailmessage(const char *mimetext,
    5.18                               message **msg);
    5.19  
    5.20 +typedef struct _dual_string_index {
    5.21 +    char* start_0;
    5.22 +    unsigned int end_0;
    5.23 +    char* start_1;
    5.24 +    unsigned int end_1;
    5.25 +} dual_string_index;
    5.26 +
    5.27 +void two_string_clear(dual_string_index* ds);
    5.28 +
    5.29  #endif
    5.30  
    5.31  #ifdef __cplusplus