@@ -55,7 +55,6 @@ static class ByteExtensions
55
55
const string AtomSafeCharacters = "!#$%&'*+-/=?^_`{|}~" ;
56
56
const string AttributeSpecials = "*'%" ; // attribute specials from rfc2184/rfc2231
57
57
const string CommentSpecials = "()\\ \r " ; // not allowed in comments
58
- const string DomainSpecials = "[]\\ \r \t " ; // not allowed in domains
59
58
const string EncodedWordSpecials = "()<>@,;:\" /[]?.=_" ; // rfc2047 5.1
60
59
const string EncodedPhraseSpecials = "!*+-/=_" ; // rfc2047 5.3
61
60
const string Specials = "()<>[]:;@\\ ,.\" " ; // rfc5322 3.2.3
@@ -70,33 +69,15 @@ static void RemoveFlags (string values, CharType bit)
70
69
table [ ( byte ) values [ i ] ] &= ~ bit ;
71
70
}
72
71
73
- static void SetFlags ( string values , CharType bit , CharType bitcopy , bool remove )
72
+ static void SetFlags ( string values , CharType bit , CharType bitcopy )
74
73
{
75
- int i ;
76
-
77
- if ( remove ) {
78
- for ( i = 0 ; i < 128 ; i ++ )
79
- table [ i ] |= bit ;
80
-
81
- for ( i = 0 ; i < values . Length ; i ++ )
82
- table [ values [ i ] ] &= ~ bit ;
83
-
84
- // Note: not actually used...
85
- //if (bitcopy != CharType.None) {
86
- // for (i = 0; i < 256; i++) {
87
- // if ((table[i] & bitcopy) != 0)
88
- // table[i] &= ~bit;
89
- // }
90
- //}
91
- } else {
92
- for ( i = 0 ; i < values . Length ; i ++ )
93
- table [ values [ i ] ] |= bit ;
94
-
95
- if ( bitcopy != CharType . None ) {
96
- for ( i = 0 ; i < 256 ; i ++ ) {
97
- if ( ( table [ i ] & bitcopy ) != 0 )
98
- table [ i ] |= bit ;
99
- }
74
+ for ( int i = 0 ; i < values . Length ; i ++ )
75
+ table [ values [ i ] ] |= bit ;
76
+
77
+ if ( bitcopy != CharType . None ) {
78
+ for ( int i = 0 ; i < 256 ; i ++ ) {
79
+ if ( ( table [ i ] & bitcopy ) != 0 )
80
+ table [ i ] |= bit ;
100
81
}
101
82
}
102
83
}
@@ -109,14 +90,16 @@ static ByteExtensions ()
109
90
table [ i ] |= CharType . IsControl ;
110
91
if ( i > 32 )
111
92
table [ i ] |= CharType . IsAttrChar ;
112
- if ( ( i >= 33 && i <= 60 ) || ( i >= 62 && i <= 126 ) || i == 32 )
93
+ if ( ( i >= 32 && i <= 60 ) || i >= 62 ) // space + all printable characters *except* '='
113
94
table [ i ] |= ( CharType . IsQuotedPrintableSafe | CharType . IsEncodedWordSafe ) ;
114
95
if ( ( i >= '0' && i <= '9' ) || ( i >= 'a' && i <= 'z' ) || ( i >= 'A' && i <= 'Z' ) )
115
96
table [ i ] |= CharType . IsEncodedPhraseSafe | CharType . IsAtom | CharType . IsPhraseAtom ;
116
97
if ( ( i >= '0' && i <= '9' ) || ( i >= 'a' && i <= 'f' ) || ( i >= 'A' && i <= 'F' ) )
117
98
table [ i ] |= CharType . IsXDigit ;
118
- if ( ( i >= 33 && i <= 57 ) || i >= 59 )
99
+ if ( ( i >= 33 && i <= 57 ) || i >= 59 ) // all printable characters *except* ':'
119
100
table [ i ] |= CharType . IsFieldText ;
101
+ if ( ( i >= 33 && i <= 90 ) || i >= 94 ) // all printable characters *except* '[', '\\', and ']'
102
+ table [ i ] |= CharType . IsDomainSafe ;
120
103
121
104
table [ i ] |= CharType . IsAscii ;
122
105
} else {
@@ -132,15 +115,14 @@ static ByteExtensions ()
132
115
table [ '\t ' ] |= CharType . IsQuotedPrintableSafe | CharType . IsBlank ;
133
116
table [ ' ' ] |= CharType . IsSpace | CharType . IsBlank ;
134
117
135
- SetFlags ( Whitespace , CharType . IsWhitespace , CharType . None , false ) ;
136
- SetFlags ( AtomSafeCharacters , CharType . IsAtom | CharType . IsPhraseAtom , CharType . None , false ) ;
137
- SetFlags ( TokenSpecials , CharType . IsTokenSpecial , CharType . IsControl , false ) ;
138
- SetFlags ( Specials , CharType . IsSpecial , CharType . None , false ) ;
139
- SetFlags ( DomainSpecials , CharType . IsDomainSafe , CharType . None , true ) ;
118
+ SetFlags ( Whitespace , CharType . IsWhitespace , CharType . None ) ;
119
+ SetFlags ( AtomSafeCharacters , CharType . IsAtom | CharType . IsPhraseAtom , CharType . None ) ;
120
+ SetFlags ( TokenSpecials , CharType . IsTokenSpecial , CharType . IsControl ) ;
121
+ SetFlags ( Specials , CharType . IsSpecial , CharType . None ) ;
140
122
RemoveFlags ( Specials , CharType . IsAtom | CharType . IsPhraseAtom ) ;
141
123
RemoveFlags ( EncodedWordSpecials , CharType . IsEncodedWordSafe ) ;
142
124
RemoveFlags ( AttributeSpecials + TokenSpecials , CharType . IsAttrChar ) ;
143
- SetFlags ( EncodedPhraseSpecials , CharType . IsEncodedPhraseSafe , CharType . None , false ) ;
125
+ SetFlags ( EncodedPhraseSpecials , CharType . IsEncodedPhraseSafe , CharType . None ) ;
144
126
145
127
// Note: Allow '[' and ']' in the display-name of a mailbox address
146
128
table [ '[' ] |= CharType . IsPhraseAtom ;
0 commit comments