Beispiel #1
0
   private static int SkipQuotedString(
 string str,
 int index,
 int endIndex,
 StringBuilder builder,  // receives the unescaped version of the string
 QuotedStringRule rule) {
     int startIndex = index;
     int valueBLength = (builder == null) ? 0 : builder.Length;
     index = (rule != QuotedStringRule.Rfc5322) ? index :
       HeaderParser.ParseCFWS(str, index, endIndex, null);
     if (!(index < endIndex && str[index] == '"')) {
       if (builder != null) {
         builder.Length = valueBLength;
       }
       return startIndex;  // not a valid quoted-string
     }
     ++index;
     while (index < endIndex) {
       int i2 = index;
       if (rule == QuotedStringRule.Http) {
         if (str[index] == ' ' || str[index] == '\t') {
           if (builder != null) {
             builder.Append(str[index]);
           }
           ++index;
           continue;
         }
       } else if (rule == QuotedStringRule.Rfc5322) {
         // Skip tabs, spaces, and folding whitespace
         i2 = ParseFWSLax(str, index, endIndex, builder);
       }
       index = i2;
       char c = str[index];
       if (c == '"') { // end of quoted-string
         ++index;
         // NOTE: Don't skip CFWS even if the rule is Rfc5322
         return index;
       }
       int oldIndex = index;
       index = SkipQtextOrQuotedPair(str, index, endIndex, rule);
       if (index == oldIndex) {
         if (builder != null) {
           builder.Remove(valueBLength, (builder.Length)-valueBLength);
         }
         return startIndex;
       }
       if (builder != null) {
         // this is a qtext or quoted-pair, so
         // append the last character read
         builder.Append(str[index - 1]);
       }
     }
     if (builder != null) {
       builder.Remove(valueBLength, (builder.Length)-valueBLength);
     }
     return startIndex;  // not a valid quoted-string
   }
   private static int skipQtextOrQuotedPair(
 string s, int index, int endIndex, QuotedStringRule rule)
   {
       if(index>=endIndex)return index;
       int i2;
       if(rule==QuotedStringRule.Http){
         char c=s[index];
         if(c<0x100 && c>=0x21 && c!='\\' && c!='"')
       return index+1;
         i2=skipQuotedPair(s,index,endIndex);
         if(index!=i2)return i2;
         return i2;
       } else if(rule==QuotedStringRule.Rfc5322){
         i2=skipQtext(s,index,endIndex);
         if(index!=i2)return i2;
         index=i2;
         i2=skipQuotedPair(s,index,endIndex);
         if(index!=i2)return i2;
         return i2;
       } else if(rule==QuotedStringRule.Smtp){
         char c=s[index];
         if(c>=0x20 && c<=0x7E && c!='\\' && c!='"')
       return index+1;
         i2=skipQuotedPairSMTP(s,index,endIndex);
         if(index!=i2)return i2;
         return i2;
       } else
         throw new ArgumentException(rule.ToString());
   }
Beispiel #3
0
 private static int SkipQtextOrQuotedPair(
   string s,
   int index,
   int endIndex,
   QuotedStringRule rule) {
   if (index >= endIndex) {
     return index;
   }
   int i2;
   if (rule == QuotedStringRule.Http) {
     char c = s[index];
     // NOTE: Space and tab were handled earlier;
     // bytes higher than 0x7f are part of obs-text
     if (c < 0x100 && c >= 0x21 && c != 0x7F && c != '\\' && c != '"') {
       return index + 1;
     }
     i2 = SkipQuotedPair(s, index, endIndex);
     return i2;
   }
   if (rule == QuotedStringRule.Rfc5322) {
     i2 = index;
     // qtext (RFC5322 sec. 3.2.1)
     if (i2 < endIndex) {
       char c = s[i2];
       // Non-ASCII (allowed in internationalized email headers under
       // RFC6532)
       if ((c & 0xfc00) == 0xd800 && i2 + 1 < endIndex && s[i2 + 1] >=
         0xdc00 && s[i2 + 1] <= 0xdfff) {
         i2 += 2;
       } else if ((c & 0xf800) == 0xd800) {
         // unchanged; it's a bare surrogate
       } else if (c >= 0x80) {
         ++i2;
       }
       if (c >= 33 && c <= 126 && c != '\\' && c != '"') {
         ++i2;
       }
       // obs-qtext (same as obs-ctext)
       if ((c < 0x20 && c != 0x00 && c != 0x09 && c != 0x0a && c != 0x0d) ||
         c == 0x7f) {
         ++i2;
       }
     }
     if (index != i2) {
       return i2;
     }
     index = i2;
     i2 = HeaderParser.ParseQuotedPair(s, index, endIndex, null);
     return i2;
   }
   throw new ArgumentException(rule.ToString());
 }
   internal static int skipQuotedString(
 string s,
 int index,
 int endIndex,
 StringBuilder builder, // receives the unescaped version of the _string
 QuotedStringRule rule // rule to follow for quoted _string
 )
   {
       int startIndex=index;
       int bLength=(builder==null) ? 0 : builder.Length;
       index=(rule!=QuotedStringRule.Rfc5322) ? index : skipCFWS(s,index,endIndex,null);
       if(!(index<endIndex && s[index]=='"')){
         if(builder!=null) {
       builder.Length=(bLength);
         }
         return startIndex; // not a valid quoted-_string
       }
       index++;
       while(index<endIndex){
         int i2=index;
         if(rule==QuotedStringRule.Http) {
       i2=skipLws(s,index,endIndex,builder);
         } else if(rule==QuotedStringRule.Rfc5322) {
       i2=skipFws(s,index,endIndex,builder);
         }
         index=i2;
         char c=s[index];
         if(c=='"'){ // end of quoted-_string
       index++;
       if(rule==QuotedStringRule.Rfc5322)
         return skipCFWS(s,index,endIndex,null);
       else
         return index;
         }
         int oldIndex=index;
         index=skipQtextOrQuotedPair(s,index,endIndex,rule);
         if(index==oldIndex){
       if(builder!=null) {
         builder.Remove(bLength,(builder.Length)-(bLength));
       }
       return startIndex;
         }
         if(builder!=null){
       // this is a qtext or quoted-pair, so
       // append the last character read
       builder.Append(s[index-1]);
         }
       }
       if(builder!=null) {
         builder.Remove(bLength,(builder.Length)-(bLength));
       }
       return startIndex; // not a valid quoted-_string
   }