Ejemplo n.º 1
0
        BodyPartSplit(string response)
        {
            ImapMessageBodyPartList Parts = new ImapMessageBodyPartList();
            int i     = 0;
            int index = 1;
            int count = 0;

            do
            {
                int next = index;
                do
                {
                    if (response[next] == '(')
                    {
                        i++;
                    }
                    else if (response[next] == ')')
                    {
                        i--;
                    }
                    next++;
                } while (i > 0 || response[next - 1] != ')');
                if (i >= 0 && response[index] == '(')
                {
                    count++;
                    // Parse nested body parts
                    if (response.Substring(index, next - index).StartsWith("(("))
                    {
                        ImapMessageBodyPartList temp = BodyPartSplit(response.Substring(index, next));
                        for (int j = 0; j < temp.Count; j++)
                        {
                            temp[j].BodyPart = count.ToString() + "." + temp[j].BodyPart;
                            Parts.Add(temp[j]);
                        }
                    }
                    else
                    {
                        ImapMessageBodyPart Part = new ImapMessageBodyPart(response.Substring(index, next - index));
                        Part.BodyPart = count.ToString();
                        Parts.Add(Part);
                    }
                }
                else if (Parts.Count == 0)
                {
                    ImapMessageBodyPart Part = new ImapMessageBodyPart(response);
                    Part.BodyPart = "1";
                    Parts.Add(Part);
                }
                index = next;
            } while (i >= 0);
            return(Parts);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        private void createFile(ImapMessageBodyPart imapMessageBodyPart, MailMessageFilter mailMessageFilter, SavedMails sm)
        {
            string message = "";

            try
            {
                if (imapMessageBodyPart.FileName.Equals(""))
                {
                    return;
                }

                System.Text.Encoding      encodingTR = System.Text.Encoding.GetEncoding("ISO-8859-9");
                System.Text.ASCIIEncoding encoding   = new System.Text.ASCIIEncoding();



                if (imapMessageBodyPart.FileName.Contains("?"))
                {
                    string[] dm = imapMessageBodyPart.FileName.Split('?');
                    message = imapMessageBodyPart.FileName;
                    dm[3]   = dm[3].Replace("=FC", "ü");
                    dm[3]   = dm[3].Replace("=DC", "Ü");
                    dm[3]   = dm[3].Replace("=F0", "ğ");
                    dm[3]   = dm[3].Replace("=D0", "Ğ");
                    dm[3]   = dm[3].Replace("=F6", "ö");
                    dm[3]   = dm[3].Replace("=D6", "Ö");
                    dm[3]   = dm[3].Replace("=E7", "ç");
                    dm[3]   = dm[3].Replace("=C7", "Ç");
                    dm[3]   = dm[3].Replace("=FD", "ı");
                    dm[3]   = dm[3].Replace("=DD", "İ");
                    dm[3]   = dm[3].Replace("=FE", "ş");
                    dm[3]   = dm[3].Replace("=DE", "Ş");
                    dm[3]   = dm[3].Replace("_", " ");
                    dm[3]   = dm[3].Replace("=5F", "_");

                    imapMessageBodyPart.FileName = dm[3];
                }
                string temp = "";
                try
                {
                    temp  = imapMessageBodyPart.FileName.Substring(0, imapMessageBodyPart.FileName.LastIndexOf('.'));
                    temp  = temp + "_" + DateTime.Today.Year + DateTime.Today.Month.ToString().PadLeft(2, '0') + DateTime.Today.Day.ToString().PadLeft(2, '0') + "_" + DateTime.Now.Hour.ToString().PadLeft(2, '0') + DateTime.Now.Minute.ToString().PadLeft(2, '0') + DateTime.Now.Second.ToString().PadLeft(2, '0');
                    temp += imapMessageBodyPart.FileName.Substring(imapMessageBodyPart.FileName.LastIndexOf('.'), imapMessageBodyPart.FileName.Length - imapMessageBodyPart.FileName.LastIndexOf('.'));
                }
                catch
                {
                    sm.ExceptionType = 1;
                    sm.SavedFiles.Add(new SavedFiles());
                    ((SavedFiles)sm.SavedFiles[sm.SavedFiles.Count - 1]).FileName = "";
                    ((SavedFiles)sm.SavedFiles[sm.SavedFiles.Count - 1]).Size     = 0;
                    return;
                }
                //nevzat:path.combine şeklinde değiştirdim.
                if (!Directory.Exists(mailMessageFilter.DestinationPath))
                {
                    Directory.CreateDirectory(mailMessageFilter.DestinationPath);
                }

                string fullPath = Path.Combine(mailMessageFilter.DestinationPath, temp);//mailMessageFilter.DestinationPath.EndsWith("\\") ? mailMessageFilter.DestinationPath : (mailMessageFilter.DestinationPath + "\\") + temp;
                using (BinaryWriter binWriter = new BinaryWriter(File.Open(fullPath, FileMode.Append), encodingTR))
                {
                    byte[] b;
                    string result = "";
                    try
                    {
                        if (imapMessageBodyPart.Data.Length != 0)
                        {
                            b = System.Convert.FromBase64String(imapMessageBodyPart.Data.Substring(0, imapMessageBodyPart.Data.Length - 1));
                        }
                        else
                        {
                            b = System.Convert.FromBase64String("");
                        }
                        result = encodingTR.GetString(b);
                    }
                    catch
                    {
                        result = imapMessageBodyPart.Data;
                    }

                    binWriter.Write(encodingTR.GetBytes(result));
                    binWriter.Close();
                    //nevzat: maildeki isim değil, kaydedilen dosya adı şeklinde değiştirdim
                    m_CreatedFileList.AppendLine(fullPath /*imapMessageBodyPart.FileName*/);
                    sm.SavedFiles.Add(new SavedFiles());
                    ((SavedFiles)sm.SavedFiles[sm.SavedFiles.Count - 1]).FileName = temp;
                    ((SavedFiles)sm.SavedFiles[sm.SavedFiles.Count - 1]).Size     = result.Length;
                }
            }
            catch (Exception ex)
            {
                sm.ExceptionType = 1;
                sm.SavedFiles.Add(new SavedFiles());
                ((SavedFiles)sm.SavedFiles[sm.SavedFiles.Count - 1]).FileName = "";
                ((SavedFiles)sm.SavedFiles[sm.SavedFiles.Count - 1]).Size     = 0;
                return;
            }
        }