コード例 #1
0
ファイル: ValueParser.cs プロジェクト: Rhombulus/Mime
 public void ParseParameterValue(ref MimeStringList value, ref bool goodValue, bool handleISO2022)
 {
     var mimeStringList = new MimeStringList();
     goodValue = true;
     while (position != end || this.ParseNextLine()) {
         var ch = bytes[position];
         switch (ch) {
             case 34:
                 value.Reset();
                 mimeStringList.Reset();
                 this.ParseQString(true, ref value, handleISO2022);
                 return;
             case 40:
                 this.ParseCFWS(true, ref mimeStringList, handleISO2022);
                 continue;
             default:
                 if (!MimeScan.IsLWSP(ch)) {
                     if (ch == 59)
                         return;
                     var offset = position;
                     do {
                         var bytesUsed = 1;
                         if (!MimeScan.IsToken(ch)) {
                             if (allowUTF8 && ch >= 128) {
                                 if (!MimeScan.IsUTF8NonASCII(bytes, position, end, out bytesUsed)) {
                                     bytesUsed = 1;
                                     goodValue = false;
                                 }
                             } else
                                 goodValue = false;
                         }
                         position += bytesUsed;
                         if (position != end) {
                             ch = bytes[position];
                             switch (ch) {
                                 case 59:
                                 case 40:
                                     goto label_17;
                                 default:
                                     continue;
                             }
                         }
                         break;
                     } while (!MimeScan.IsLWSP(ch));
                     label_17:
                     value.TakeOverAppend(ref mimeStringList);
                     value.AppendFragment(new MimeString(bytes, offset, position - offset));
                     continue;
                 }
                 goto case (byte) 40;
         }
     }
 }
コード例 #2
0
ファイル: MimeAddressParser.cs プロジェクト: Rhombulus/Mime
 public AddressParserResult ParseNextMailbox(ref MimeStringList displayName, ref MimeStringList address)
 {
     var addressParserResult = groupInProgress ? AddressParserResult.GroupInProgress : AddressParserResult.Mailbox;
     var parserStage = ParserStage.BEGIN;
     var mimeStringList1 = new MimeStringList();
     var mimeStringList2 = new MimeStringList();
     var mimeStringList3 = new MimeStringList();
     var flag1 = true;
     var flag2 = false;
     var ignoreNextByte = false;
     if (!this.Initialized)
         throw new System.InvalidOperationException(Resources.Strings.AddressParserNotInitialized);
     while (true) {
         byte num1;
         do {
             do {
                 do {
                     do {
                         if (valueParser.ParseToDelimiter(ignoreNextByte, !flag1 && flag2, ref mimeStringList1)) {
                             flag2 = false;
                             ignoreNextByte = false;
                             flag1 = false;
                         }
                         num1 = valueParser.ParseGet();
                         var num2 = num1;
                         if (num2 <= 34U) {
                             switch (num2) {
                                 case 0:
                                     goto label_24;
                                 case 9:
                                 case 10:
                                 case 13:
                                 case 32:
                                     valueParser.ParseWhitespace(false, ref mimeStringList3);
                                     flag2 = true;
                                     continue;
                                 case 34:
                                     valueParser.ParseUnget();
                                     if (mimeStringList1.Length != 0 && !flag1)
                                         valueParser.ParseAppendSpace(ref mimeStringList1);
                                     else
                                         flag1 = false;
                                     valueParser.ParseQString(true, ref mimeStringList1, true);
                                     flag2 = true;
                                     continue;
                             }
                         } else if (num2 <= 46U) {
                             switch (num2) {
                                 case 40:
                                     if (mimeStringList2.Length != 0)
                                         mimeStringList2.Reset();
                                     valueParser.ParseUnget();
                                     if (ignoreComments) {
                                         valueParser.ParseComment(true, false, ref mimeStringList2, true);
                                         if (flag2)
                                             mimeStringList1.AppendFragment(new MimeString(" "));
                                         mimeStringList1.TakeOverAppend(ref mimeStringList2);
                                     } else
                                         valueParser.ParseComment(true, true, ref mimeStringList2, true);
                                     flag2 = true;
                                     continue;
                                 case 44:
                                     goto label_24;
                                 case 46:
                                     valueParser.ParseAppendLastByte(ref mimeStringList1);
                                     flag1 = true;
                                     continue;
                             }
                         } else {
                             switch (num2) {
                                 case 58:
                                 case 59:
                                 case 60:
                                 case 62:
                                 case 64:
                                 case 91:
                                 case 93:
                                     goto label_24;
                             }
                         }
                         valueParser.ParseUnget();
                         ignoreNextByte = true;
                         continue;
                         label_24:
                         switch (parserStage) {
                             case ParserStage.BEGIN:
                                 var num3 = num1;
                                 if (num3 <= 44U) {
                                     if (num3 != 0) {
                                         if (num3 != 44)
                                             goto label_41;
                                     } else
                                         goto label_40;
                                 } else {
                                     switch (num3) {
                                         case 58:
                                             continue;
                                         case 59:
                                             groupInProgress = false;
                                             addressParserResult = AddressParserResult.Mailbox;
                                             break;
                                         case 60:
                                             goto label_38;
                                         case 62:
                                             goto label_39;
                                         case 64:
                                             goto label_35;
                                         case 91:
                                             goto label_36;
                                         default:
                                             goto label_41;
                                     }
                                 }
                                 if (mimeStringList1.GetLength(4026531839U) != 0) {
                                     displayName.TakeOver(ref mimeStringList1);
                                     goto label_89;
                                 }
                                 mimeStringList1.Reset();
                                 continue;
                             case ParserStage.ANGLEADDR:
                                 goto label_42;
                             case ParserStage.ADDRSPEC:
                                 goto label_60;
                             case ParserStage.ROUTEDOMAIN:
                                 goto label_75;
                             case ParserStage.END:
                                 goto label_85;
                             default:
                                 goto label_89;
                         }
                     } while (mimeStringList1.GetLength(4026531839U) == 0);
                     displayName.TakeOver(ref mimeStringList1);
                     groupInProgress = true;
                     return AddressParserResult.GroupStart;
                     label_35:
                     var length = mimeStringList1.Length;
                     valueParser.ParseAppendLastByte(ref mimeStringList1);
                     address.TakeOver(ref mimeStringList1);
                     parserStage = ParserStage.ADDRSPEC;
                     continue;
                     label_36:
                     if (!useSquareBrackets) {
                         valueParser.ParseUnget();
                         ignoreNextByte = true;
                         continue;
                     }
                     label_38:
                     displayName.TakeOver(ref mimeStringList1);
                     parserStage = ParserStage.ANGLEADDR;
                     continue;
                     label_39:
                     mimeStringList1.Reset();
                     continue;
                     label_40:
                     displayName.TakeOver(ref mimeStringList1);
                     goto label_89;
                     label_41:
                     valueParser.ParseUnget();
                     ignoreNextByte = true;
                     continue;
                     label_42:
                     var num4 = num1;
                     if (num4 <= 44U) {
                         if (num4 != 0) {
                             if (num4 == 44)
                                 goto label_57;
                             goto label_59;
                         }
                         goto label_58;
                     }
                     switch (num4) {
                         case 58:
                             goto label_56;
                         case 60:
                             continue;
                         case 62:
                             goto label_55;
                         case 64:
                             if (mimeStringList1.Length == 0) {
                                 parserStage = ParserStage.ROUTEDOMAIN;
                                 continue;
                             }
                             valueParser.ParseAppendLastByte(ref mimeStringList1);
                             address.TakeOver(ref mimeStringList1);
                             parserStage = ParserStage.ADDRSPEC;
                             continue;
                         case 91:
                             if (!useSquareBrackets) {
                                 valueParser.ParseUnget();
                                 ignoreNextByte = true;
                                 continue;
                             }
                             goto case (byte) 60;
                         case 93:
                             goto label_53;
                         default:
                             goto label_59;
                     }
                 } while (mimeStringList1.Length == 0);
                 valueParser.ParseUnget();
                 ignoreNextByte = true;
                 continue;
                 label_53:
                 if (!useSquareBrackets) {
                     valueParser.ParseUnget();
                     ignoreNextByte = true;
                     continue;
                 }
                 label_55:
                 address.TakeOver(ref mimeStringList1);
                 parserStage = address.Length != 0 || displayName.Length != 0 ? ParserStage.END : ParserStage.BEGIN;
                 continue;
                 label_56:
                 mimeStringList1.Reset();
                 continue;
                 label_57:
                 ;
             } while (displayName.Length == 0 && mimeStringList1.Length == 0);
             label_58:
             address.TakeOver(ref mimeStringList1);
             break;
             label_59:
             valueParser.ParseUnget();
             ignoreNextByte = true;
             continue;
             label_60:
             var num5 = num1;
             if (num5 <= 44U) {
                 if (num5 != 0 && num5 != 44)
                     goto label_74;
             } else {
                 switch (num5) {
                     case 59:
                         groupInProgress = false;
                         break;
                     case 60:
                         if (displayName.Length == 0) {
                             displayName.TakeOverAppend(ref address);
                             parserStage = ParserStage.ANGLEADDR;
                             continue;
                         }
                         valueParser.ParseUnget();
                         ignoreNextByte = true;
                         continue;
                     case 62:
                         address.TakeOverAppend(ref mimeStringList1);
                         parserStage = ParserStage.END;
                         continue;
                     case 91:
                         if (mimeStringList1.Length == 0) {
                             valueParser.ParseUnget();
                             valueParser.ParseDomainLiteral(true, ref mimeStringList1);
                             address.TakeOverAppend(ref mimeStringList1);
                             parserStage = ParserStage.END;
                             continue;
                         }
                         valueParser.ParseUnget();
                         ignoreNextByte = true;
                         continue;
                     case 93:
                         if (!useSquareBrackets) {
                             valueParser.ParseUnget();
                             ignoreNextByte = true;
                             continue;
                         }
                         goto case (byte) 62;
                     default:
                         goto label_74;
                 }
             }
             address.TakeOverAppend(ref mimeStringList1);
         } while (address.Length == 0 && displayName.Length == 0 && num1 != 0);
         break;
         label_74:
         valueParser.ParseUnget();
         ignoreNextByte = true;
         continue;
         label_75:
         var num6 = num1;
         if (num6 <= 44U) {
             if (num6 != 0) {
                 if (num6 != 44)
                     goto label_84;
             } else
                 break;
         } else {
             switch (num6) {
                 case 58:
                     break;
                 case 62:
                     mimeStringList1.Reset();
                     parserStage = ParserStage.END;
                     continue;
                 case 91:
                     mimeStringList1.Reset();
                     valueParser.ParseUnget();
                     valueParser.ParseDomainLiteral(false, ref mimeStringList3);
                     continue;
                 case 93:
                     if (!useSquareBrackets) {
                         valueParser.ParseUnget();
                         ignoreNextByte = true;
                         continue;
                     }
                     goto case (byte) 62;
                 default:
                     goto label_84;
             }
         }
         mimeStringList1.Reset();
         parserStage = ParserStage.ANGLEADDR;
         continue;
         label_84:
         valueParser.ParseUnget();
         ignoreNextByte = true;
         continue;
         label_85:
         mimeStringList1.Reset();
         switch (num1) {
             case 0:
             case 44:
                 if (address.Length == 0 && displayName.Length == 0 && num1 != 0) {
                     parserStage = ParserStage.BEGIN;
                     continue;
                 }
                 goto label_89;
             case 59:
                 groupInProgress = false;
                 goto case (byte) 0;
             default:
                 continue;
         }
     }
     label_89:
     if (displayName.Length == 0 && mimeStringList2.Length != 0 && address.Length != 0)
         displayName.TakeOver(ref mimeStringList2);
     if (address.Length == 0 && displayName.Length == 0)
         addressParserResult = AddressParserResult.End;
     return addressParserResult;
 }
コード例 #3
0
ファイル: ReceivedHeader.cs プロジェクト: Rhombulus/Mime
 private void FinishClause(ref MimeString param, ref MimeStringList value, bool allowUTF8)
 {
     if (param.Length == 0)
         return;
     var sz = value.GetSz();
     var str = sz == null ? null : Internal.ByteString.BytesToString(sz, allowUTF8);
     var crcI = param.ComputeCrcI();
     if (crcI <= 2556329580U) {
         if ((int) crcI != 271896810) {
             if ((int) crcI != 2115158205) {
                 if ((int) crcI == -1738637716)
                     fromValue = str;
             } else
                 byValue = str;
         } else
             forValue = str;
     } else if ((int) crcI != -1177273070) {
         if ((int) crcI != -554265150) {
             if ((int) crcI == -18844241)
                 idValue = str;
         } else
             viaValue = str;
     } else
         withValue = str;
     value.Reset();
     param = MimeString.Empty;
 }
コード例 #4
0
ファイル: ReceivedHeader.cs プロジェクト: Rhombulus/Mime
 private void Parse()
 {
     this.Reset();
     parsed = true;
     var headerDecodingOptions = this.GetHeaderDecodingOptions();
     var valueParser = new ValueParser(this.Lines, headerDecodingOptions.AllowUTF8);
     var mimeStringList1 = new MimeStringList();
     var mimeStringList2 = new MimeStringList();
     var mimeString1 = new MimeString();
     var mimeString2 = MimeString.Empty;
     var parseState1 = ParseState.None;
     while (true) {
         valueParser.ParseWhitespace(true, ref mimeStringList1);
         var num1 = valueParser.ParseGet();
         if (num1 != 0) {
             if (59 == num1)
                 parseState1 = ParseState.Date;
             else if (40 == num1 && parseState1 == ParseState.DomainValue)
                 parseState1 = ParseState.DomainAddress;
             else {
                 valueParser.ParseUnget();
                 mimeString1 = valueParser.ParseToken();
                 if (mimeString1.Length == 0) {
                     int num2 = valueParser.ParseGet();
                     mimeStringList2.TakeOverAppend(ref mimeStringList1);
                     valueParser.ParseAppendLastByte(ref mimeStringList2);
                     continue;
                 }
                 var parseState2 = this.StateFromToken(mimeString1);
                 if (ParseState.None != parseState2)
                     parseState1 = parseState2;
             }
             switch (parseState1) {
                 case ParseState.Domain:
                 case ParseState.OptInfo:
                     if (mimeString2.Length != 0)
                         this.FinishClause(ref mimeString2, ref mimeStringList2, headerDecodingOptions.AllowUTF8);
                     else
                         mimeStringList2.Reset();
                     mimeString2 = mimeString1;
                     valueParser.ParseWhitespace(false, ref mimeStringList1);
                     mimeStringList1.Reset();
                     ++parseState1;
                     continue;
                 case ParseState.DomainValue:
                     mimeStringList2.TakeOverAppend(ref mimeStringList1);
                     mimeStringList2.AppendFragment(mimeString1);
                     continue;
                 case ParseState.DomainAddress:
                     var flag = mimeString2.CompareEqI(ParamFrom);
                     this.FinishClause(ref mimeString2, ref mimeStringList2, headerDecodingOptions.AllowUTF8);
                     mimeStringList1.Reset();
                     valueParser.ParseUnget();
                     valueParser.ParseComment(true, false, ref mimeStringList2, true);
                     var sz1 = mimeStringList2.GetSz();
                     var str = sz1 == null ? null : Internal.ByteString.BytesToString(sz1, headerDecodingOptions.AllowUTF8);
                     if (flag)
                         fromTcpInfoValue = str;
                     else
                         byTcpInfoValue = str;
                     mimeStringList2.Reset();
                     parseState1 = ParseState.None;
                     continue;
                 case ParseState.OptInfoValue:
                     mimeStringList2.TakeOverAppend(ref mimeStringList1);
                     mimeStringList2.AppendFragment(mimeString1);
                     continue;
                 case ParseState.Date:
                     this.FinishClause(ref mimeString2, ref mimeStringList2, headerDecodingOptions.AllowUTF8);
                     mimeStringList1.Reset();
                     valueParser.ParseWhitespace(false, ref mimeStringList1);
                     valueParser.ParseToEnd(ref mimeStringList2);
                     var sz2 = mimeStringList2.GetSz();
                     dateValue = sz2 == null ? null : Internal.ByteString.BytesToString(sz2, false);
                     continue;
                 case ParseState.None:
                     mimeStringList2.Reset();
                     continue;
                 default:
                     continue;
             }
         }
         break;
     }
     this.FinishClause(ref mimeString2, ref mimeStringList2, headerDecodingOptions.AllowUTF8);
 }
コード例 #5
0
ファイル: MimeStringList.cs プロジェクト: Rhombulus/Mime
 public void TakeOverAppend(ref MimeStringList list, uint mask)
 {
     if (this.Count == 0 && (int) mask == -268435456)
         this.TakeOver(ref list, mask);
     else {
         for (var index = 0; index < list.Count; ++index) {
             var refLine = list[index];
             if ((int) mask == -268435456 || ((int) refLine.Mask & (int) mask) != 0)
                 this.AppendFragment(refLine);
         }
         list.Reset();
     }
 }