Beispiel #1
0
 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;
 }
Beispiel #2
0
 internal static bool TryDecodeValue(MimeStringList lines, uint linesMask, DecodingOptions decodingOptions, out DecodingResults decodingResults, out string value)
 {
     decodingResults = new DecodingResults();
     if (lines.GetLength(linesMask) == 0) {
         value = string.Empty;
         return true;
     }
     var decodingFlags = decodingOptions.DecodingFlags;
     var enableFallback = DecodingFlags.None != (DecodingFlags.FallbackToRaw & decodingFlags);
     var allowControlCharacters = DecodingFlags.None != (DecodingFlags.AllowControlCharacters & decodingFlags);
     var enable2047 = false;
     var enableJisDetection = false;
     var enableUtf8Detection = false;
     var enableDbcsDetection = false;
     Globalization.Charset defaultCharset = null;
     var valueDecoder = new ValueDecoder(lines, linesMask);
     if ((decodingFlags & DecodingFlags.AllEncodings) == DecodingFlags.None) {
         if (!enableFallback)
             defaultCharset = Globalization.Charset.ASCII;
     } else {
         enable2047 = DecodingFlags.None != (DecodingFlags.Rfc2047 & decodingFlags);
         enableJisDetection = DecodingFlags.None != (DecodingFlags.Jis & decodingFlags);
         enableUtf8Detection = DecodingFlags.None != (DecodingFlags.Utf8 & decodingFlags);
         enableDbcsDetection = DecodingFlags.None != (DecodingFlags.Dbcs & decodingFlags);
         defaultCharset = decodingOptions.Charset;
     }
     string charsetName;
     string cultureName;
     EncodingScheme encodingScheme;
     var flag = valueDecoder.TryDecodeValue(
         defaultCharset,
         enableFallback,
         allowControlCharacters,
         enable2047,
         enableJisDetection,
         enableUtf8Detection,
         enableDbcsDetection,
         out charsetName,
         out cultureName,
         out encodingScheme,
         out value);
     decodingResults.EncodingScheme = encodingScheme;
     decodingResults.CharsetName = charsetName;
     decodingResults.CultureName = cultureName;
     decodingResults.DecodingFailed = !flag;
     return flag;
 }