SMTP message code



  • I'm getting a letter from the Exchange Server with the Cyrillian. The text of the message in the mail--Hello, peace!" There's a problem in handling this message because:

    1. Cyrillica.peace"..=F1=E2=E3
    2. When converted from Quoted Printables to 1251 (for the stream to be normal) the Latin is lost.

    So I get Russian from Quoted Printables:

    public static string DecodeQuotedPrintables(string input, Encoding encoding)
        {
            var regex = new Regex(@"\=(?<Symbol>[0-9A-Z]{2})", RegexOptions.Multiline);
            var matches = regex.Matches(input);
            var bytes = new byte[matches.Count];
    
        for (var i = 0; i &lt; matches.Count; i++)
        {
            bytes[i] = Convert.ToByte(matches[i].Groups["Symbol"].Value, 16);
        }
    
        return encoding.GetString(bytes);
    }
    

    Would you please tell the algorithm how, having a Latin woman and a crylic convert the message to keep both languages?



  • You're on the line, from the symbol to the symbol. Look at every symbol. If the symbol code is relevant from 33 to 60; or from 62 to 126; or 32 or 9, you put it in the white buffer. If it's a symbol of equals, then it could be either a translation of the line (i.e., "r\n) or a double-digit sixteenth number. If after "=" there's a line transfer, you're missing that line translation. If after "=" there's a sixteenth number, then you put it in the white buffer. At the end of the day, you're transferring the bowl received to the line with the code. About:

    static string FromQuotePrintable(string s, Encoding e) {
          using (var ms = new MemoryStream(s.Length)) {
            for (int i = 0; i < s.Length; ++i) {
              byte c = (byte)s[i];
              if (c >= 33 && c <= 60 || c >= 62 && c <= 126 || c==' ' || c=='\t') {
                ms.WriteByte(c);
                continue;
              }
              if (c == '=') {
                i += 2;
                if (s[i - 1] == '\r' && s[i] == '\n') {
                  continue;
                }
                ms.WriteByte(byte.Parse(s.Substring(i - 1, 2), System.Globalization.NumberStyles.HexNumber));
              }
            }
            return e.GetString(ms.GetBuffer(), 0, (int)ms.Length);
          }
        }
    

    This code doesn't have an inconsistency check for Quote Printable. So if the entry line doesn't match it, there may be different mistakes out of line, mistakes in moving from the sixteenth line to the White and others. Coding description here: http://kunegin.com/ref2/email/mime03.htm

    In principle, by speed and memory, it would be more effective to translate from the 2nd 16th symbols into the bayte, without the pluging of the underground. It's a little more complicated.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2