Beispiel #1
0
        private string GetLocalPathInbox()
        {
            string curpath = Directory.GetCurrentDirectory();

            FileManager Rcsv = new FileManager();

            System.Globalization.CultureInfo cur = new
                                                   System.Globalization.CultureInfo("en-US");
            //////System.Globalization.CultureInfo("en-US");

            string Sday    = Today.ToString("yyyyMMdd", cur);
            string Mailbox = String.Format("{0}\\MailBox");//\\{ 1}", curpath, Sday);

            Rcsv.ScanFilePath(Mailbox);

            return(Mailbox);
        }
Beispiel #2
0
        public Boolean SaveMail(Mail oMail, int i, ref String SavePath)
        {
            ////rea un directorio y carpeta llamada mailbox
            ////para guardar los correos en ella
            string curpath  = Directory.GetCurrentDirectory();
            string mailbox  = String.Format("{0}\\inbox", curpath);
            string FilePath = "";

            //teTime Today = DateTime.Now;


            //FilterMail ObjFil = new FilterMail();

            // si la carpeta no existe la crea(Mailbox)
            if (!Directory.Exists(mailbox))
            {
                Directory.CreateDirectory(mailbox);
            }
            try
            {
                FileManager Rcsv = new FileManager();
                //Rutas Para Guardar los Archivos de respaldo y Grabacion del mensaje
                //string PathHistoric = @"\\10.177.1.230\MAILACF$\RPETC_ACF"; //+ SToday;
                string PathHistoric = SavePath;
                System.Globalization.CultureInfo cur = new
                                                       System.Globalization.CultureInfo("en-US");
                string sdate = Today.ToString("yyyyMMddHHmmss", cur);
                string Sday  = Today.ToString("yyyyMMdd", cur);

                //System.Globalization.CultureInfo cur = new
                //System.Globalization.CultureInfo("en-US");
                //string sdate = Today.ToString("yyyyMMddHHmmss", cur);
                string fileName = String.Format("{0}\\{1}{2}{3}.msg",
                                                mailbox, sdate, Today.Millisecond.ToString("d3"), i);
                FilePath = fileName;


                ///crea la ruta del dia en que se recibio
                string PathHist = String.Format(PathHistoric + Sday,
                                                PathHistoric, sdate, Today.Millisecond.ToString("d3"), i);

                ///crea la ruta del mensaje de respaaldo a guardar

                string HistFile = String.Format("{0}" + Sday + "\\{1}{2}{3}.msg",
                                                PathHistoric, sdate, Today.Millisecond.ToString("d3"), i);

                //determina si el directorio existe , sino lo crea.
                Rcsv.ScanFilePath(PathHistoric);
                Rcsv.ScanFilePath(PathHist);

                if (fileName != null)
                {
                    //oMail.SaveAs(fileName, true);guardar como eml
                    oMail.SaveAsOMSG(fileName, true, true);
                }
                if (HistFile != null)
                {
                    //oMail.SaveAs(HistFile, true, true);guardar como eml
                    oMail.SaveAsOMSG(HistFile, true, true);
                    SavePath = HistFile;
                }
                if (fileName != null && PathHistoric != null)
                {
                    //GUARDO EXITOSAMENTE

                    //Logs.Log("ReceiveMail.SaveMail", "Guardo Exitosamente el MSG");
                    /////-------- delarar salida de servidor: Marcado de correos descargados y cerraar conexion
                    //  PoClient

                    return(true);
                }
                else
                {
                    Logs.Log("ReceiveMail.SaveMail", "ERROR- No se logró Guardar el MSG");
                    return(false);
                }
            }
            catch (Exception ep)
            {
                Logs.Log("ReceiveMail.SaveMail", ep.Message.ToString());
                return(false);
                //throw;
            }

            //return true;
        }
Beispiel #3
0
        private String GetDestino(Mail oMail, String Tipe)
        {
            try
            {
                //Rutas Para Guardar los Archivos de respaldo y Grabacion del mensaje
                string Destino = @"\\10.177.1.220\MAILACF\";  /// RPETC_ACF"; //+ SToday;
                //string PathHistoric = SavePath;
                System.Globalization.CultureInfo cur = new
                                                       System.Globalization.CultureInfo("en-US");
                string sdate = Today.ToString("yyyyMMddHHmmss", cur);
                string Sday  = Today.ToString("yyyyMMdd", cur);

                FilterMail fl    = new FilterMail();
                String     Ofrom = (oMail.From.ToString());
                //ReceiveMail rv = new ReceiveMail();
                fl.ShopEmail(ref Ofrom);


                switch (Tipe)
                {
                case "1":        //////-  --1 = RPTC
                    Destino = Destino + @"RPETC";
                    MailProcessed++;
                    break;

                case "2":       //////-- - 2 = XML
                    Destino = Destino + @"XML\" + Ofrom;
                    MailProcessed++;
                    break;

                case "3":      //////-- - 3 = DICOM
                    Destino = Destino + @"DICOM";
                    MailProcessed++;
                    break;

                case "4":      //////-- - 4 = RESPALDOS
                    Destino = Destino + @"RESPALDOS\" + Ofrom;
                    MailProcessed++;
                    break;

                default:      //// descartados
                    Destino = Destino + @"DESCARTADOS";
                    MailPurging++;
                    break;
                }

                Destino = String.Format("{0}\\{1}", Destino, Sday);

                /////crea la ruta del dia en que se recibio
                //string PathHist = String.Format(PathHistoric + Sday,
                //PathHistoric, sdate, Today.Millisecond.ToString("d3"), i);

                ///crea la ruta del mensaje de respaaldo a guardar

                //string HistFile = String.Format("{0}" + Sday + "\\{1}{2}{3}.msg",
                //           PathHistoric, sdate, Today.Millisecond.ToString("d3"), i);

                //determina si el directorio existe , sino lo crea.
                FileManager Rcsv = new FileManager();
                Rcsv.ScanFilePath(Destino);
                //sv.ScanFilePath(PathHist);

                return(Destino);
            } catch (Exception ep)
            {
                Logs.Log("ReceiveMail.GetDestino", ep.Message.ToString());
                return("");
            }

            //return "";
        }
Beispiel #4
0
        private Boolean ParseMailsFromInbox()
        {
            try
            {
                Logs.Log("ReceiveMail.ParseMailsFromInbox", "Tratando de Parsear Correos - Iniciando....");

                //List<string> Files = new List<string>();
                Mail oMail = new Mail("TryIt");
                //String MailPath = @""+Itm;
                /*oMail.LoadOMSG(Itm);  */  ////carga el msg como un objeto
                //oMail.Load(Itm, true);

                System.Globalization.CultureInfo cur = new
                                                       System.Globalization.CultureInfo("en-US");
                //string sdate = Today.ToString("yyyyMMddHHmmss", cur);
                string Sday = Today.ToString("yyyyMMdd", cur);

                string curpath = Directory.GetCurrentDirectory();
                string Mailbox = String.Format("{0}\\MailBox\\{1}", curpath, Sday);

                FileManager Rcsv = new FileManager();
                Rcsv.ScanFilePath(Mailbox);

                /////Get all *.eml files in specified folder and parse it one by one.
                string[] files = Directory.GetFiles(Mailbox, "*.eml");

                //foreach (string file in Directory.EnumerateFiles(Mailbox, "*.eml"))
                //{
                //    String Paths = Path.GetFullPath(file);
                //    Files.Add(Paths);
                //    //oMail.Load(file, true);
                //}

                FilterMail fl    = new FilterMail();
                int        Count = files.Length;
                MailCounting = files.Length;
                Logs.Log("Se contaron: " + MailCounting, " Correos disponibles en Inbox");
                for (int i = 0; i < Count; i++)
                {
                    String FileRoute = files[i];
                    String fname     = Path.GetFileName(FileRoute);
                    oMail.Load(files[i], true);
                    fl.Filter(oMail, i, fname);

                    String Tipe = (fl.IsType);

                    String Origen  = files[i];
                    String Destino = GetDestino(oMail, Tipe);

                    MoveMail(Origen, Destino);
                    //if(Tipe==1 || Tipe == 2)
                    //    MailProcessed++;

                    //if (Tipe == 3 || Tipe == 4)
                    //{
                    //    MailProcessed++;
                    //}
                    //else
                    //{
                    //    MailPurging++;
                    //}
                }

                Logs.Log("Procesados: " + MailProcessed, "de: " + MailCounting + "Descartados: " + MailPurging);


                //foreach (string itm in Files)
                //{

                //    oMail.Load(itm, true);
                //    fl.Filter(oMail,itm);


                //}

                //PendingLoadMail(Files);

                //int Count = files.Length;
                //for (int i = 0; i < Count; i++)
                //{
                //    //ParseEmail(files[i]);
                //    FilterMail fl = new FilterMail();
                //    fl.ProcessMail(files);
                //    fl.PendingProcess();
                //    //ObjFil.Filter(oMail, i);
                //}

                //Logs.Log("ReceiveMail.ParseMailsFromInbox", "Correos Parseados Correctamente. Cantidad: " + Count);
                return(true);
            }
            catch (Exception e)
            {
                Logs.Log("ReceiveMail.ParseMailsFromInbox", "Error en Parsing Mails Desde Inbox: " + e.Message.ToString());
                return(false);
            }
        }
Beispiel #5
0
        //public System.Globalization.CultureInfo cur = new
        //public System.Globalization.CultureInfo("en-US");
        //public string Stoday = Today.ToString("yyyyMMdd", cur);
        //public string LogDirectory = Directory.GetCurrentDirectory();
        //LogDirectory = String.Format("{0}\\Log\\" + Stoday + "\\", LogDirectory);//+"Log_" + Stoday +".txt", LogDirectory);
        //public String FilePath = (LogDirectory + "Log_" + Stoday + ".txt");
        //using (StreamReader r = File.OpenText("log.txt"))
        //{
        //    DumpLog(r);
        //}
        //}

        public static void Log(string logMessage, string e)
        {
            FileManager Fm = new FileManager();

            System.Globalization.CultureInfo cur = new
                                                   System.Globalization.CultureInfo("en-US");
            string Stoday       = Today.ToString("yyyyMMdd", cur);
            string LogDirectory = Directory.GetCurrentDirectory();

            LogDirectory = String.Format("{0}\\Log\\" + Stoday + "\\", LogDirectory);//+"Log_" + Stoday +".txt", LogDirectory);
            String FilePath = (LogDirectory + "Log_" + Stoday + ".txt");

            //if (Directory.Exists(LogDirectory))
            //{
            //    Directory.CreateDirectory(LogDirectory);
            //Fm.ScanFilePath(LogDirectory);
            /////Fm.ScanFilePath(PathHist);
            if (Fm.ScanFilePath(LogDirectory) == true)
            {
                using (StreamWriter w = File.AppendText(FilePath))

                {
                    if (File.Exists(FilePath))
                    {
                        w.Write("\r\nLog Entry : ");
                        w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),
                                    DateTime.Now.ToLongDateString());
                        w.WriteLine("  :");
                        w.WriteLine("  :{0} {1}", logMessage, e);
                        w.WriteLine("-------------------------------");
                        w.Flush();
                        w.Close();
                        w.Dispose();
                    }
                }
            }


            //StreamWriter w =new StreamWriter(FilePath);
            //////if (!Directory.Exists(LogDirectory))
            //////{
            //////    Directory.CreateDirectory(LogDirectory);
            //////    if (!File.Exists(FilePath))
            //////    {
            //////        File.CreateText(FilePath);
            //////        w = File.CreateText(FilePath);

            //////        w.Flush();
            //////        w.Close();
            //////        w.Dispose();

            //////        using (StreamWriter sw = new StreamWriter(FilePath)
            //////        using (w = File.AppendText(FilePath))
            //////        {
            //////            string logMessage = string.Empty;
            //////            Exception e;
            //////            Log(logMessage, e, w);
            //////            Log("Test2", w);
            //////            w.Write("\r\nLog Entry : ");
            //////            w.WriteLine("{0} {1}", DateTime.Now.ToLongTimeString(),
            //////                DateTime.Now.ToLongDateString());
            //////            w.WriteLine("  :");
            //////            w.WriteLine("  :{0} {1}", logMessage, e);
            //////            w.WriteLine("-------------------------------");
            //////            w.Flush();
            //////            w.Close();
            //////            w.Dispose();


            //////            objFileLogger.Flush();
            //////            objFileLogger.Close();
            //////            objFileLogger.Dispose()
            //////        }

            //////    }
            //////}

            //w.Close();
            //StreamWriter w = new StreamWriter();
            //StreamWriter w =new StreamWriter(FilePath);
        }