コード例 #1
0
ファイル: Expression.cs プロジェクト: mrShpit/GEMC
 public override string UseEncoding(interpreterContext context)
 {
     if (context.Output != null)
     {
         return Encoding.UTF8.GetString(context.Output.ToArray());
     }
     else
     {
         return string.Empty;
     }
 }
コード例 #2
0
ファイル: Expression.cs プロジェクト: mrShpit/GEMC
        public void Interpret(interpreterContext context)
        {
            List<byte> output = new List<byte>();
            var i = 0;
            try
            {
                while (i < context.Input.Length - 2)
                {
                    if (context.Input[i] == '=' && context.Input[i + 1] == '\r' && context.Input[i + 2] == '\n')
                    {
                        //Skip
                        i += 3;
                    }
                    else if (context.Input[i] == '=')
                    {
                        string shex = context.Input;
                        shex = shex.Substring(i + 1, 2);
                        int hex = Convert.ToInt32(shex, 16);
                        byte b = Convert.ToByte(hex);
                        output.Add(b);
                        i += 3;
                    }
                    else
                    {
                        output.Add((byte)context.Input[i]);
                        i++;
                    }
                }

                context.Output = output;
            }
            catch
            {
                context.Output = null;
            }
        }
コード例 #3
0
ファイル: PostClient.cs プロジェクト: mrShpit/GEMC
        public Letter CheckLetterByIMAP(Profile user, int letterNum)
        {
            Letter newLetter = new Letter();
            newLetter.SetId();
            newLetter.ProfileId = user.Id;
            newLetter.To = user.Adress;
            newLetter.Category = "Inbox";

            bool subjectFound = false;
            bool dateFound = false;
            bool fromFound = false;

            ImapConsole console = new ImapConsole();
            console.SetSSLConnection(user);
            console.SendCommand(new ImapAuthenticate(user));
            console.ExecuteCommand();

            this.ImapRequest("$ SELECT INBOX\r\n");

            console.SendCommand(new ImapGetHeaderOfLetter(letterNum));
            List<string> letterHeader = (List<string>)console.ExecuteCommand();

            foreach (string line in letterHeader)
            {
                if (!fromFound && line.Contains("From: "))
                {
                    string thisLine = line;
                    if (line.Contains("<"))
                    {
                        thisLine = line.Substring(line.IndexOf('<') + 1, line.IndexOf('>') - line.IndexOf('<') - 1);
                        newLetter.From = thisLine;
                    }
                    else
                    {
                        newLetter.From = thisLine.Substring(6);
                    }

                    fromFound = true;
                }

                if (!dateFound && line.Length > 6 && line.Substring(0, 6) == "Date: ")
                {
                    string thisLine = line;
                    if (line.Contains("+"))
                    {
                        thisLine = line.Substring(0, line.IndexOf('+'));
                    }
                    else if (line.Contains("-"))
                    {
                        thisLine = line.Substring(0, line.IndexOf('-'));
                    }
                    
                    newLetter.SendingTime = Convert.ToDateTime(thisLine.Substring(6));
                    dateFound = true;
                }

                if (!subjectFound && line.Contains("Subject: "))
                {
                    newLetter.Subject = line.Substring(9).Replace("\r", string.Empty);
                    if (newLetter.Subject.Substring(0, 5) == "=?utf")
                    {
                        newLetter.Subject = newLetter.Subject.Substring(10, newLetter.Subject.Length - 10);
                        interpreterContext iC = new interpreterContext(newLetter.Subject);
                        DefaultExpression ex = new DefaultExpression();
                        ex.Interpret(iC);
                        newLetter.Subject = ex.UseEncoding(iC);
                    }

                    subjectFound = true;
                }

                if (subjectFound && dateFound && fromFound)
                {
                    break;
                }
            }

            console.SetSSLConnection(user);
            console.SendCommand(new ImapAuthenticate(user));
            console.ExecuteCommand();
            this.ImapRequest("$ SELECT INBOX\r\n");

            console.SendCommand(new ImapGetTextOfLetter(letterNum));
            newLetter.Body = (string)console.ExecuteCommand();

            return newLetter;
        }
コード例 #4
0
ファイル: Expression.cs プロジェクト: mrShpit/GEMC
 public override string UseEncoding(interpreterContext context)
 {
     return Encoding.GetEncoding("Shift_JIS").GetString(context.Output.ToArray());
 }
コード例 #5
0
ファイル: Expression.cs プロジェクト: mrShpit/GEMC
 public abstract string UseEncoding(interpreterContext context);