stowing changes to work on other bugs peg-mime
authorKrista Grothoff <krista@pep-project.org>
Fri, 23 Sep 2016 13:18:15 +0200
branchpeg-mime
changeset 11840c430ea338dc
parent 1183 9c5df64440d0
child 1207 1257bd577baf
stowing changes to work on other bugs
mime-parser/Makefile
mime-parser/mailmime.leg
src/mailmime.c
     1.1 --- a/mime-parser/Makefile	Wed Sep 21 22:15:18 2016 +0200
     1.2 +++ b/mime-parser/Makefile	Fri Sep 23 13:18:15 2016 +0200
     1.3 @@ -4,7 +4,7 @@
     1.4  	cp mailmime.leg.c.src ../src/.
     1.5  
     1.6  generate: 
     1.7 -	leg mailmime.leg -o mailmime.leg.c.src
     1.8 +	leg -P mailmime.leg -o mailmime.leg.c.src
     1.9  
    1.10  .PHONY: clean
    1.11  
     2.1 --- a/mime-parser/mailmime.leg	Wed Sep 21 22:15:18 2016 +0200
     2.2 +++ b/mime-parser/mailmime.leg	Fri Sep 23 13:18:15 2016 +0200
     2.3 @@ -11,11 +11,12 @@
     2.4  
     2.5  Mail                    =      ( Header )+ CRLF ( Body )? EOF
     2.6  
     2.7 -Header                  =     ( < MIMEHeader >  | 
     2.8 -                                < MessageHeader >  | 
     2.9 -                                < GenericHeader > )
    2.10 +Header                  =     ( MIMEHeader  | 
    2.11 +                                MessageHeader  | 
    2.12 +                                GenericHeader )
    2.13  
    2.14 -GenericHeader           =      HeaderKey COLON_PLUS_WS < HeaderText > 
    2.15 +#FIXME: Do we need to strip the last CRLF from the headertext?
    2.16 +GenericHeader           =      HeaderKey COLON_PLUS_WS <HeaderText> 
    2.17                                      {
    2.18                                          stringpair_list_add(yy->parsed_msg->opt_fields, new_stringpair(yy->tmp_key, yytext));
    2.19                                          free(yy->tmp_key);
    2.20 @@ -31,10 +32,11 @@
    2.21                                      {
    2.22                                          yy->tmp_key = strdup(yytext);
    2.23                                      }                        
    2.24 -HeaderPhrase            =      EncodedWord | Word
    2.25 +
    2.26  HeaderText              =      HeaderLine ( HeaderCont )* 
    2.27  HeaderCont              =      Whitespace HeaderLine
    2.28 -HeaderLine              =      HeaderPhrase* CRLF
    2.29 +HeaderPhrase            =      EncodedWord | Word
    2.30 +HeaderLine              =      (HeaderPhrase | Whitespace)* CRLF
    2.31  
    2.32  #MIME Header Blocks
    2.33  
    2.34 @@ -125,22 +127,22 @@
    2.35  ExtValue                =      Value
    2.36  
    2.37  # Message-related headers (per RFC2822)
    2.38 -MessageHeader           =     ( MessageIDHeader |
    2.39 +MessageHeader           =     (( MessageIDHeader |
    2.40                                  MessageToHeader |
    2.41                                  MessageFromHeader |
    2.42                                  MessageCCHeader |
    2.43                                  MessageBCCHeader |
    2.44 -                                MessageSubjHeader |
    2.45                                  MessageReplyToHeader |
    2.46                                  MessageInReplyToHeader |
    2.47 -                                MessageRefsHeader ) CRLF      
    2.48 +                                MessageRefsHeader ) CRLF) 
    2.49 +                                | MessageSubjHeader
    2.50                                  
    2.51  MessageIDHeader         =      MessageIDKey COLON_PLUS_WS IDString
    2.52 -MessageToHeader         =      MessageToKey COLON_PLUS_WS < ToString >  
    2.53 +MessageToHeader         =      MessageToKey COLON_PLUS_WS ToString  
    2.54  MessageFromHeader       =      MessageFromKey COLON_PLUS_WS FromString
    2.55  MessageCCHeader         =      MessageCCKey COLON_PLUS_WS CCString
    2.56  MessageBCCHeader        =      MessageBCCKey COLON_PLUS_WS BCCString
    2.57 -MessageSubjHeader       =      MessageSubjKey COLON_PLUS_WS Whitespace* SubjString
    2.58 +MessageSubjHeader       =      MessageSubjKey COLON_PLUS_WS SubjString
    2.59  MessageReplyToHeader    =      MessageReplyToKey COLON_PLUS_WS ReplyToString
    2.60  MessageInReplyToHeader  =      MessageInReplyToKey COLON_PLUS_WS InReplyToString
    2.61  MessageRefsHeader       =      MessageRefsKey COLON_PLUS_WS RefsString
    2.62 @@ -153,9 +155,10 @@
    2.63  MessageReplyToKey       =      'Reply-To'
    2.64  MessageInReplyToKey     =      'In-Reply-To'
    2.65  MessageRefsKey          =      'References'  
    2.66 -IDString                =      < MsgID > 
    2.67 +IDString                =       MsgID 
    2.68                                      {
    2.69 -                                        yy->parsed_msg->id = strdup(yytext);
    2.70 +                                        yy->parsed_msg->id = strdup(yy->curr_msg_id_list->value);
    2.71 +                                        free(yy->curr_msg_id_list);
    2.72                                      }
    2.73  ToString                =      AddressList 
    2.74                                      {
    2.75 @@ -250,7 +253,16 @@
    2.76                                      } 
    2.77                                  | <d:DisplayName a:AngleAddr> 
    2.78                                      { 
    2.79 -                                        $$ = (void*)new_identity(a, NULL, strdup(yytext), d); 
    2.80 +                                        int a_size = strlen(a);
    2.81 +                                        int d_size = strlen(d);
    2.82 +                                        int userid_len = a_size + d_size + 4;
    2.83 +                                        char* userid = (char*)malloc(sizeof(char) * (userid_len + 1));
    2.84 +                                        strcpy(userid, d);
    2.85 +                                        strncat(userid, " <", userid_len - d_size);
    2.86 +                                        strncat(userid, a, userid_len - (d_size + 2));
    2.87 +                                        strncat(userid, ">", 1);
    2.88 +                                        userid[userid_len] = '\0';
    2.89 +                                        $$ = (void*)new_identity(a, NULL, userid, d); 
    2.90                                      }
    2.91  AngleAddr               =      CFWS? "<" <AddrSpec> ">" CFWS? 
    2.92                                      {
    2.93 @@ -262,7 +274,23 @@
    2.94                                      }
    2.95  # FIXME: Process group
    2.96  Group                   =      DisplayName ":" (MailboxList | CFWS)? ";" CFWS?
    2.97 -DisplayName             =      < Phrase > {$$ = strdup(yytext);}
    2.98 +DisplayName             =      < Phrase > 
    2.99 +                                    {
   2.100 +                                        /* Unfortunately, the trailing CFWS sticks with the Phrase */
   2.101 +                                        size_t final_length = yyleng;
   2.102 +                                        char check_curr;
   2.103 +                                        for (check_curr = yytext[final_length - 1];
   2.104 +                                             (check_curr == ' ' || check_curr == '\t') && final_length >= 0;
   2.105 +                                             check_curr = yytext[--final_length - 1]);
   2.106 +                                            
   2.107 +                                        char* retval = (char*)malloc(sizeof(char) * (final_length + 1));
   2.108 +                                        strncpy(retval, yytext, final_length);
   2.109 +                                        retval[final_length] = '\0';
   2.110 +
   2.111 +                                        $$ = retval;
   2.112 +                                        
   2.113 +                                        
   2.114 +                                    }
   2.115  MailboxList             =      (Mailbox ("," Mailbox)*) | ObsMBoxList
   2.116  AddressList             =      (Address ("," Address)*) | ObsAddrList 
   2.117  
   2.118 @@ -285,7 +313,7 @@
   2.119  ObsAddrList             =      (Address? CFWS? "," CFWS?)+ Address?
   2.120                        
   2.121                        
   2.122 -# RFC2822 Message ID - FIXME - what should this look like?
   2.123 +# RFC2822 Message ID
   2.124  MsgID                   =       CFWS? "<" < IDLeft "@" IDRight > ">" CFWS? 
   2.125                                      { 
   2.126                                          if (!yy->curr_msg_id_list)
   2.127 @@ -300,15 +328,16 @@
   2.128  ObsIDLeft               =      LocalPart
   2.129  ObsIDRight              =      Domain
   2.130                        
   2.131 -Body                    =      PlainBody
   2.132 +Body                    =      MIMEBody | PlainBody
   2.133  PlainBody               =      .* EOF
   2.134  
   2.135 +MIMEBody            =      
   2.136  Encapsulation       =      Delimiter BodyPart CRLF
   2.137  CloseDelimiter      =      Delimiter "--"
   2.138  Delimiter           =      CRLF DashBoundary
   2.139  BodyPart            =      MIMEHeader+ (CRLF OCTET*)?
   2.140  DashBoundary        =      "--" Boundary
   2.141 -Boundary            =      < BChars* BCharsNoSpace >
   2.142 +Boundary            =      BChars* BCharsNoSpace
   2.143  BCharsNoSpace       =      BChars | Space
   2.144  BChars              =      Digit | Alpha | "'" | "(" | ")" |
   2.145                              "+" | "_" | "," | "-" | "." |
   2.146 @@ -334,7 +363,7 @@
   2.147  AlphaNum            =      Alpha | Digit
   2.148  Alpha               =      [a-zA-Z]
   2.149  Digit               =      [0-9]
   2.150 -Symbol              =      OrdinarySymbol | COLON_PLUS_WS
   2.151 +Symbol              =      OrdinarySymbol | COLON
   2.152  Whitespace          =      Space+
   2.153  Space               =      [' ' '\t']
   2.154  
   2.155 @@ -362,8 +391,8 @@
   2.156  
   2.157  HexDigit                =      (Digit | "A" | "B" | "C" | "D" | "E" | "F")
   2.158  
   2.159 -EncodedWord             =      <"=?" Charset ("*" Language)? "?" EncodedText "?="> |
   2.160 -                                <"=?" Charset "?" Encoding "?" EncodedText "?=">
   2.161 +EncodedWord             =      "=?" Charset ("*" Language)? "?" EncodedText "?=" |
   2.162 +                                "=?" Charset "?" Encoding "?" EncodedText "?="
   2.163                                  
   2.164  Encoding                =      [Q q] | [B b]
   2.165  
     3.1 --- a/src/mailmime.c	Wed Sep 21 22:15:18 2016 +0200
     3.2 +++ b/src/mailmime.c	Fri Sep 23 13:18:15 2016 +0200
     3.3 @@ -25,6 +25,7 @@
     3.4      ctx.input_str = mimetext;
     3.5      ctx.index_consumed = 0;
     3.6      ctx.parsed_msg = new_message(PEP_dir_incoming);
     3.7 +    ctx.parsed_msg->opt_fields = new_stringpair_list(NULL);
     3.8      ctx.curr_address_list = NULL;
     3.9      ctx.curr_msg_id_list = NULL;
    3.10      ctx.tmp_key = NULL;