/// <summary> /// /// </summary> private void loadFilterFromFile() { String theFile = AppDomain.CurrentDomain.BaseDirectory + FILTER_FILE_NAME; try { DataSet ds = new DataSet(); ds.ReadXml(theFile); m_FilterTable = ds.Tables[0]; m_MailMessageFilters = new MailMessageFilter[m_FilterTable.Rows.Count]; for (int i = 0; i < m_FilterTable.Rows.Count; i++) { m_MailMessageFilters[i] = new MailMessageFilter(); m_MailMessageFilters[i].From = m_FilterTable.Rows[i]["From"].ToString(); m_MailMessageFilters[i].Subject = m_FilterTable.Rows[i]["Subject"].ToString(); m_MailMessageFilters[i].FileName = m_FilterTable.Rows[i]["FileName"].ToString(); m_MailMessageFilters[i].DestinationPath = m_FilterTable.Rows[i]["DestinationPath"].ToString(); } } catch (XmlException xEx) { throw new Exception("Mail Filter parametre dosyası uygun formatta değil! Kontrol ediniz.", xEx); } catch (FileNotFoundException fex) { throw new Exception(theFile + " parametre dosyası bulunamadı. Lütfen kontrol ediniz!", fex); } catch (Exception ex) { throw new Exception("Mail Filter Parametre dosyasının okunması sırasında hata oluştu!", ex); } }
/// <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; } }