Example #1
0
        public MimeMessage(bool autoAppendHeaderVersion)
        {
            mimeHeader = new StrDictionary();

            if (autoAppendHeaderVersion)
                MimeHeader.Add("MIME-Version", "1.0");
        }
Example #2
0
        /*
         *  EmailEnabled: 1
         *  MemberIdHigh: 123456
         *  MemberIdLow: -1234567890
         *  lang_preference: 2052
         *  country: US
         *  Kid: 0
         *  Flags: 1073742915
         *  sid: 72652
         *  ClientIP: XXX.XXX.XXX.XXX
         *  Nickname: New
         *  RouteInfo: msnp://XXX.XXX.XXX.XXX/013557A5
         */
        internal void UpdateProfile(StrDictionary hdr)
        {
            foreach (StrKeyValuePair pair in hdr)
            {
                msgProfile[String.Copy(pair.Key)] = String.Copy(pair.Value);
            }

            ValidProfile = true;

            if (msgProfile.ContainsKey("Nickname"))
            {
                SetNickName(msgProfile["Nickname"]);
            }

            OnProfileReceived(EventArgs.Empty);
        }
Example #3
0
        /*
            EmailEnabled: 1
            MemberIdHigh: 123456
            MemberIdLow: -1234567890
            lang_preference: 2052
            country: US
            Kid: 0
            Flags: 1073742915
            sid: 72652
            ClientIP: XXX.XXX.XXX.XXX
            Nickname: New
            RouteInfo: msnp://XXX.XXX.XXX.XXX/013557A5
        */
        internal void UpdateProfile(StrDictionary hdr)
        {
            foreach (StrKeyValuePair pair in hdr)
            {
                msgProfile[String.Copy(pair.Key)] = String.Copy(pair.Value);
            }

            ValidProfile = true;

            if (msgProfile.ContainsKey("Nickname"))
                SetNickName(msgProfile["Nickname"]);

            OnProfileReceived(EventArgs.Empty);
        }
Example #4
0
        /// <summary>
        /// Parses the raw header to set the member variables
        /// </summary>
        internal void ParseHeader(StrDictionary mimeHeader)
        {
            // example header: "X-MMS-IM-Format: FN=Microsoft%20Sans%20Serif; EF=I; CO=000000; CS=0; PF=22"
            if (mimeHeader.ContainsKey(MIMEHeaderStrings.X_MMS_IM_Format))
            {
                string[] fields  = mimeHeader[MIMEHeaderStrings.X_MMS_IM_Format].Split(';');
                string   FNValue = string.Empty;
                string   EFValue = string.Empty;
                string   CSValue = string.Empty;
                string   COValue = string.Empty;
                string   PFValue = string.Empty;

                foreach (string field in fields)
                {
                    if (field.Trim().IndexOf("FN=") == 0)
                    {
                        FNValue = field.Split('=')[1];
                    }

                    if (field.Trim().IndexOf("EF=") == 0)
                    {
                        EFValue = field.Split('=')[1];
                    }

                    if (field.Trim().IndexOf("CS=") == 0)
                    {
                        CSValue = field.Split('=')[1];
                    }

                    if (field.Trim().IndexOf("CO=") == 0)
                    {
                        COValue = field.Split('=')[1];
                    }

                    if (field.Trim().IndexOf("PF=") == 0)
                    {
                        PFValue = field.Split('=')[1];
                    }
                }

                if (FNValue != string.Empty)
                {
                    Font = HttpUtility.UrlDecode(FNValue);
                }

                if (EFValue != string.Empty)
                {
                    Decorations = TextDecorations.None;
                    string dec = EFValue;
                    if (dec.IndexOf('I') >= 0)
                    {
                        Decorations |= TextDecorations.Italic;
                    }
                    if (dec.IndexOf('B') >= 0)
                    {
                        Decorations |= TextDecorations.Bold;
                    }
                    if (dec.IndexOf('U') >= 0)
                    {
                        Decorations |= TextDecorations.Underline;
                    }
                    if (dec.IndexOf('S') >= 0)
                    {
                        Decorations |= TextDecorations.Strike;
                    }
                }

                if (COValue != string.Empty)
                {
                    string color = COValue;

                    if (color.Length < 6)
                    {
                        for (int i = 0; i < 6 - COValue.Length; i++)
                        {
                            color = "0" + color;
                        }
                    }

                    try
                    {
                        if (color.Length >= 6)
                        {
                            Color = System.Drawing.Color.FromArgb(
                                int.Parse(color.Substring(4, 2), System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture), // R
                                int.Parse(color.Substring(2, 2), System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture), // G
                                int.Parse(color.Substring(0, 2), System.Globalization.NumberStyles.HexNumber, System.Globalization.CultureInfo.InvariantCulture)  // B
                                );
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                if (CSValue != string.Empty)
                {
                    try
                    {
                        CharSet = (MessageCharSet)int.Parse(CSValue, System.Globalization.CultureInfo.InvariantCulture);
                    }
                    catch (Exception)
                    {
                    }
                }

                if (PFValue != string.Empty)
                {
                }

                if (mimeHeader.ContainsKey(MIMEHeaderStrings.P4_Context))
                {
                    this.customNickname = mimeHeader[MIMEHeaderStrings.P4_Context];
                }
            }
        }
Example #5
0
 public MimeMessage()
 {
     mimeHeader = new StrDictionary();
     MimeHeader.Add("MIME-Version", "1.0");
 }
Example #6
0
        protected static StrDictionary ParseMime(IEnumerator enumerator, byte[] data)
        {
            StrDictionary table = new StrDictionary();

            string name = null;
            string val = null;

            int startpos = 0;
            int endpos = 0;
            bool gettingval = false;

            while (enumerator.MoveNext())
            {
                if ((byte)enumerator.Current == 13)
                {
                    // no name specified -> end of header (presumably \r\n\r\n)
                    if (startpos == endpos && !gettingval)
                    {
                        enumerator.MoveNext();
                        return table;
                    }

                    val = Encoding.UTF8.GetString(data, startpos, endpos - startpos);

                    if (!table.ContainsKey(name))
                        table.Add(name, val);

                    startpos = endpos + 2;
                    gettingval = false;
                }
                else if ((byte)enumerator.Current == 58) //:
                {
                    if (!gettingval)
                    {
                        gettingval = true;
                        name = Encoding.UTF8.GetString(data, startpos, endpos - startpos);
                        startpos = endpos + 2;
                        enumerator.MoveNext();
                        endpos++;
                    }
                }
                endpos++;
            }

            return table;
        }
Example #7
0
        public override void ParseBytes(byte[] data)
        {
            // parse the header
            IEnumerator enumerator = data.GetEnumerator();
            mimeHeader = ParseMime(enumerator, data);

            // get the rest of the message
            MemoryStream memStream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(memStream);
            while (enumerator.MoveNext())
                writer.Write((byte)enumerator.Current);
            InnerBody = memStream.ToArray();
            memStream.Close();
        }