コード例 #1
0
        static public IReportHandler GetPrinter(int outputType, string path, Stream reportOutputStream)
        {
            IReportHandler reportHandler;

#if !NETCORE
            if (outputType == OUTPUT_RVIEWER_NATIVE)
            {
                reportHandler = new GxReportBuilderNative(path, reportOutputStream);
            }
            else if (outputType == OUTPUT_RVIEWER_DLL)
            {
                reportHandler = new GxReportBuilderDll(path);
            }
            else
#endif
            if (outputType == OUTPUT_PDF)
            {
                try
                {
#if !NETCORE
                    Assembly assem = null;

                    try
                    {
                        assem = Assembly.Load("GxPdfReportsCS");
                    }
                    catch (FileNotFoundException ex)
                    {
                        GXLogging.Debug(log, ex.Message, ex);
                    }

                    if (assem == null)
                    {
                        assem = Assembly.Load("GxPdfReportsI");
                    }
                    Type classType = assem.GetType("GeneXus.Printer.GxReportBuilderPdf", false, true);
                    reportHandler = (IReportHandler)Activator.CreateInstance(classType, new Object[] { path, reportOutputStream });
#else
                    reportHandler = (IReportHandler)(ClassLoader.FindInstance("GxPdfReportsCS", "GeneXus.Printer", "GxReportBuilderPdf", new Object[] { path, reportOutputStream }, null));
#endif
                }
                catch (TargetInvocationException ex)
                {
                    if (ex.InnerException != null)
                    {
                        GXLogging.Error(log, "Load GxPdfReportsI Error", ex.InnerException);
                        throw ex.InnerException;
                    }
                    else
                    {
                        throw ex;
                    }
                }
                catch (Exception ex)
                {
                    GXLogging.Error(log, "Load GxPdfReportsI Error", ex);
                    throw ex;
                }
            }
            else
            {
                throw new Exception("Unrecognized report type: " + outputType);
            }
            return(reportHandler);
        }
コード例 #2
0
 private static void LogError(string msg)
 {
     GXLogging.Error(log, msg);
 }
コード例 #3
0
ファイル: POP3Session.cs プロジェクト: jechague/DotNetClasses
        private void Receive(GXMailMessage msg)
        {
            if (lastReadMessage == count)
            {
                throw new NoMessagesException();
            }

            msg.Clear();

            char pSep = System.IO.Path.DirectorySeparatorChar;

            if (!attachDir.EndsWith(pSep.ToString()))
            {
                attachDir += pSep.ToString();
            }

            SendNL("RETR " + (++lastReadMessage));
            GXLogging.Debug(log, "Receive " + lastReadMessage);

            MailMessage message = null;

            try
            {
                mailReader = new RFC822Reader(new RFC822EndReader(new SecureNetworkStream(connection)));
                message    = new MailMessage(mailReader, attachDir, readerTimeout);
                message.DownloadAttachments = this.DownloadAttachments;
                message.ReadAllMessage();
            }
            catch (InvalidMessageException ime)
            {
#if DEBUG
                GXLogging.Error(log, "Receive error", ime);
#endif
                throw new GXMailException(ime.Message, GXInternetConstants.MAIL_InvalidValue);
            }
            catch (CouldNotSaveAttachmentException dae)
            {
#if DEBUG
                GXLogging.Error(log, "Receive error", dae);
#endif
                throw new GXMailException(dae.Message, GXInternetConstants.MAIL_CantSaveAttachment);
            }
            catch (InvalidAttachmentException iae)
            {
#if DEBUG
                GXLogging.Error(log, "Receive error", iae);
#endif
                throw new GXMailException(iae.Message, GXInternetConstants.MAIL_InvalidAttachment);
            }
            catch (TimeoutExceededException toe)
            {
#if DEBUG
                GXLogging.Error(log, "Receive error", toe);
#endif
                throw new GXMailException(toe.Message, GXInternetConstants.MAIL_TimeoutExceeded);
            }
            catch (Exception exc)
            {
#if DEBUG
                GXLogging.Error(log, "Receive error", exc);
#endif
                throw new GXMailException(exc.Message, MailConstants.MAIL_ConnectionLost);
            }
            try
            {
                if (message != null)
                {
                    GXMailRecipientCollection msgFrom = new GXMailRecipientCollection();
                    message.SetMessageRecipients(msgFrom, GXInternetConstants.FROM);
                    if (msgFrom.Count > 0)
                    {
                        msg.From = msgFrom.Item(1);
                    }
                    message.SetMessageRecipients(msg.ReplyTo, GXInternetConstants.REPLY_TO);
                    message.SetMessageRecipients(msg.To, GXInternetConstants.TO);
                    message.SetMessageRecipients(msg.CC, GXInternetConstants.CC);
                    msg.Headers      = message.Keys;
                    msg.DateSent     = message.GetDateSent();
                    msg.DateReceived = message.GetDateReceived();

                    msg.Subject = message.GetMessageSubject();

                    msg.Text     = message.GetMessageText();
                    msg.HTMLText = message.GetMessageHtmlText();

                    message.SetMessageAttachments(msg.Attachments);
                }
            }
            catch (Exception exc)
            {
                GXLogging.Error(log, "Error Receiving", exc);
                throw new GXMailException(exc.Message, GXInternetConstants.MAIL_InvalidValue);
            }
        }
コード例 #4
0
        public static string HtmlPreview(Object obj, string query, string textType, string preTag, string postTag, int fragmentSize, int maxNumFragments)
        {
            string         text;
            GxSilentTrnSdt silent = obj as GxSilentTrnSdt;
            GxFile         file   = obj as GxFile;

            if (silent != null)
            {
                text = (silent).Transaction.ToString();
            }
            else if (file != null)
            {
                text = DocumentHandler.GetText(file.GetAbsoluteName(), System.IO.Path.GetExtension(file.GetAbsoluteName()));
            }
            else if (textType.ToLower().StartsWith("htm"))
            {
                text = new NTidyHTMLHandler().GetTextFromString(obj.ToString());
            }
            else
            {
                text = obj.ToString();
            }
            if (!string.IsNullOrEmpty(query) && !string.IsNullOrEmpty(text))
            {
                if (qp == null)
                {
                    qp = new QueryParser(Lucene.Net.Util.Version.LUCENE_24, IndexRecord.CONTENTFIELD, Indexer.CreateAnalyzer());
                    qp.DefaultOperator        = QueryParser.Operator.AND;
                    qp.MultiTermRewriteMethod = MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE;
                }
                Query unReWrittenQuery = qp.Parse(query);
                Query q = unReWrittenQuery;
                try
                {
                    if (reader == null)
                    {
                        reader = Indexer.Reader;
                    }
                    if (!queries.TryGetValue(query, out q))
                    {
                        q = unReWrittenQuery.Rewrite(reader);//required to expand search terms (for the usage of highlighting with wildcards)

                        if (queries.Count == int.MaxValue)
                        {
                            queries.Clear();
                        }
                        queries[query] = q;
                    }
                }
                catch (Exception ex)
                {
                    GXLogging.Error(log, "HTMLPreview error", ex);
                }
                QueryScorer scorer = new QueryScorer(q);

                SimpleHTMLFormatter formatter   = new SimpleHTMLFormatter(preTag, postTag);
                Highlighter         highlighter = new Highlighter(formatter, scorer);
                IFragmenter         fragmenter  = new SimpleFragmenter(fragmentSize);

                highlighter.TextFragmenter = fragmenter;
                TokenStream tokenStream = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_24).TokenStream("Content", new StringReader(text));

                String result = highlighter.GetBestFragments(tokenStream, text, maxNumFragments, "...");
                return(result);
            }
            else
            {
                return(text);
            }
        }
コード例 #5
0
        //ns = kb Namespace
        //clssWithoutNamespace = fullname genexus object (includes module), p.e. genexus.sd.synchronization.offlineeventreplicator
        static public Type FindType(string defaultAssemblyName, string ns, string clssWithoutNamespace, Assembly defaultAssembly)
        {
            string clss    = string.IsNullOrEmpty(ns) ? clssWithoutNamespace : string.Format("{0}.{1}", ns, clssWithoutNamespace);
            Type   objType = null;
            string appNS;

            loadedAssemblies.TryGetValue(clss, out objType);
            if (objType == null)
            {
#if NETCORE
                var asl = new AssemblyLoader(FileUtil.GetStartupDirectory());
#endif
                if (defaultAssembly != null)
                {
                    try
                    {
                        objType = defaultAssembly.GetType(clss);
                    }
                    catch
                    {
                        GXLogging.Error(log, "Failed to load type: " + clss + ", assembly: " + defaultAssembly.FullName);
                    }
                }

                try
                {
                    AssemblyName defaultAssemblyNameObj = new AssemblyName(defaultAssemblyName);
                    if (objType == null)
                    {
#if NETCORE
                        Assembly assem = asl.LoadFromAssemblyName(defaultAssemblyNameObj);
                        objType = assem.GetType(clss);
#else
                        objType = Assembly.Load(defaultAssemblyNameObj).GetType(clss);
#endif
                    }
                }
                catch (Exception ex)
                {
                    GXLogging.Error(log, "Failed to load type: " + clss + ", assembly: " + defaultAssemblyName, ex);
                }
                try
                {
                    if (objType == null)
                    {
                        if (Assembly.GetEntryAssembly() != null)
                        {
                            objType = Assembly.GetEntryAssembly().GetType(clss);
                        }
                    }
                }
                catch
                {
                    GXLogging.Error(log, "Failed to load type: " + clss + " from entryAssembly");
                }
                try
                {
                    if (objType == null)
                    {
                        objType = Assembly.GetCallingAssembly().GetType(clss);
                    }
                }
                catch
                {
                    GXLogging.Error(log, "Failed to load type: " + clss + " from callingAssembly");
                }

                if (objType == null && !string.IsNullOrEmpty(ns) && Config.GetValueOf("AppMainNamespace", out appNS))
                {
                    if (ns != appNS)
                    {
                        return(FindType(defaultAssemblyName, appNS, clssWithoutNamespace, defaultAssembly));
                    }
                }
                if (objType == null)
                {
                    GXLogging.Warn(log, "Find Instance in CurrentDomain");

                    foreach (Assembly asby in AppDomain.CurrentDomain.GetAssemblies())
                    {
                        objType = asby.GetType(clss);
                        if (objType != null)
                        {
                            break;
                        }
                    }
                }
                if (objType == null && !string.IsNullOrEmpty(ns))
                {
                    if (defaultAssemblyName.Contains(","))
                    {
                        string[] parts = defaultAssemblyName.Split(',');
                        if (parts.Length == 2)
                        {
                            defaultAssemblyName = parts[1];
                            clss = parts[0];
                        }
                        return(FindType(defaultAssemblyName, string.Empty, clss, defaultAssembly));
                    }
                }

                if (objType == null)
                {
                    GXLogging.Debug(log, "Find class in assemblies in directory " + FileUtil.GetStartupDirectory());

                    ArrayList files = new ArrayList();
                    files.AddRange(Directory.GetFiles(FileUtil.GetStartupDirectory(), "*.dll"));
#if !NETCORE
                    files.AddRange(Directory.GetFiles(FileUtil.GetStartupDirectory(), "*.exe"));
#endif
                    foreach (string file in files)
                    {
                        GXLogging.Debug(log, "Find class " + clss + ", assembly: " + file);
                        try
                        {
#if !NETCORE
                            objType = Assembly.LoadFrom(file).GetType(clss);
#else
                            Assembly assem = asl.LoadFromAssemblyName(new AssemblyName(Path.GetFileNameWithoutExtension(file)));
                            objType = assem.GetType(clss);
#endif
                            if (objType != null)
                            {
                                break;
                            }
                        }
                        catch (BadImageFormatException)
                        {
                            // It is not an .Net assembly
                        }
                    }

                    if (objType == null)
                    {
                        GXLogging.Error(log, "Failed to load type: " + clss + " from currentdomain");
                        throw new GxClassLoaderException("Failed to load type: " + clss);
                    }
                }

                loadedAssemblies[clss] = objType;
            }
            return(objType);
        }
コード例 #6
0
ファイル: WSHandler.cs プロジェクト: jechague/DotNetClasses
 private static void LogError(string msg, Exception e = null)
 {
     GXLogging.Error(log, e, msg);
 }
コード例 #7
0
 public Task WebException(Exception ex)
 {
     GXLogging.Error(log, "WebException", ex);
     return(SetError("500", ex.Message));
 }
コード例 #8
0
        private void CopyAttachments(Attachments fromList, GxStringCollection toList)
        {
            GXLogging.Debug(log, "Copying Attachments");
            int    lastBar  = 0;
            string fileName = "";
            Fields fields;
            Field  field;

            for (int i = 1; i <= (int)fromList.Count; i++)
            {
                Attachment attachment = (Attachment)fromList.get_Item(i);
                if (!string.IsNullOrEmpty(attachDir))
                {
                    toList.Add(attachment.Name.ToString());
                    fields = (Fields)attachment.Fields;

                    // Long filename
                    try
                    {                    // 0x3707001E = PR_ATTACH_LONG_FILENAME
                        field    = (Field)fields.get_Item(0x3707001E, optional);
                        fileName = field.Value.ToString();
                    }
                    catch (Exception) {}

                    if (string.IsNullOrEmpty(fileName))
                    {                    // Long filename - UNICODE
                        try
                        {                // 0x3707001E + 1 = PR_ATTACH_LONG_FILENAME
                            field    = (Field)fields.get_Item(0x3707001E + 1, optional);
                            fileName = field.Value.ToString();
                        }
                        catch (Exception) {}
                    }

                    if (string.IsNullOrEmpty(fileName))
                    {                    // Short filename
                        try
                        {                // 0x3704001E = PR_ATTACH_LONG_FILENAME
                            field    = (Field)fields.get_Item(0x3704001E + 1, optional);
                            fileName = field.Value.ToString();
                        }
                        catch (Exception) {}
                    }

                    if (string.IsNullOrEmpty(fileName))
                    {                    // Short filename - UNICODE
                        try
                        {                // 0x3704001E + 1 = PR_ATTACH_LONG_FILENAME
                            field    = (Field)fields.get_Item(0x3704001E + 1, optional);
                            fileName = field.Value.ToString();
                        }
                        catch (Exception) {}
                    }

                    if (string.IsNullOrEmpty(fileName))
                    {
                        fileName = attachment.Source.ToString();
                    }

                    if (string.IsNullOrEmpty(fileName))
                    {
                        fileName = attachment.Name.ToString();
                    }

                    lastBar = fileName.LastIndexOf("\\");
                    if (lastBar != -1)
                    {
                        fileName = fileName.Substring(lastBar + 1);
                    }

                    char pSep = System.IO.Path.DirectorySeparatorChar;
                    if (!attachDir.EndsWith(pSep.ToString()))
                    {
                        attachDir += pSep.ToString();
                    }

                    try
                    {
                        attachment.WriteToFile(attachDir + fileName);
                    }
                    catch (Exception exc)
                    {
                        GXLogging.Error(log, "Could not save attachment", exc);
                        throw new GXMailException("Could not save attachment", 16);
                    }
                }
                if (string.IsNullOrEmpty(fileName))
                {
                    fileName = attachment.Name.ToString();
                }
                lastBar = fileName.LastIndexOf("\\");
                if (lastBar != -1)
                {
                    toList.Add(fileName.Substring(lastBar + 1));
                }
                else
                {
                    toList.Add(fileName);
                }
            }
        }
コード例 #9
0
        private void ChangeFolder(string strFolder)
        {
            GXLogging.Debug(log, "Changing folder");
            if (newMessages < 0 || newMessages > 1)
            {
                GXLogging.Error(log, "Invalid NewMessages value");
                throw new GXMailException("Invalid NewMessages value", 27);
            }

            Folder defaultFolder = null;
            Folder parentFolder  = null;
            Folder folder        = null;
            bool   foundFolder   = false;

            inFolder = false;
            message  = null;

            if (loggedIn)
            {
                try
                {
                    defaultFolder = (Folder)session.GetDefaultFolder(CdoDefaultFolderTypes.CdoDefaultFolderInbox);

                    if ((defaultFolder != null) && !defaultFolder.Name.Equals(""))
                    {
                        parentFolder = GetParentFolder(defaultFolder, ref foundFolder);

                        string[] foldersArr = strFolder.Split(new char[] { '\\' });
                        for (int i = 0; i < foldersArr.Length; i++)
                        {
                            if (string.IsNullOrEmpty(foldersArr[i]))
                            {
                                continue;
                            }
                            else if (foldersArr[i].Equals("."))
                            {
                                if (foundFolder)
                                {
                                    folder = parentFolder;
                                }
                            }
                            else if (foldersArr[i].Equals(".."))
                            {
                                if (!foundFolder)
                                {
                                    throw new GXMailException("Could not open folder " + strFolder, 5);
                                }
                                else
                                {
                                    foundFolder = false;
                                    folder      = GetParentFolder(parentFolder, ref foundFolder);
                                }
                            }
                            else if (foldersArr[i].Equals("Inbox"))
                            {
                                folder = (Folder)session.GetDefaultFolder(CdoDefaultFolderTypes.CdoDefaultFolderInbox);
                            }
                            else if (foldersArr[i].Equals("Outbox"))
                            {
                                folder = (Folder)session.GetDefaultFolder(CdoDefaultFolderTypes.CdoDefaultFolderOutbox);
                            }
                            else if (foldersArr[i].Equals("Sent Items"))
                            {
                                folder = (Folder)session.GetDefaultFolder(CdoDefaultFolderTypes.CdoDefaultFolderSentItems);
                            }
                            else if (foldersArr[i].Equals("Deleted Items"))
                            {
                                folder = (Folder)session.GetDefaultFolder(CdoDefaultFolderTypes.CdoDefaultFolderDeletedItems);
                            }
                            else if (folder != null)
                            {
                                foundFolder = false;
                                folder      = GetFolder((Folders)folder.Folders, foldersArr[i], ref foundFolder);
                                if (!foundFolder)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                foundFolder = false;
                                folder      = GetFolder((Folders)parentFolder.Folders, foldersArr[i], ref foundFolder);
                                if (!foundFolder)
                                {
                                    break;
                                }
                            }
                        }
                    }
                }
                catch (Exception exc)
                {
                    GXLogging.Error(log, "Could not open folder", exc);
                    throw new GXMailException("Could not open folder", 5);
                }
                if (folder == null)
                {
                    folder = defaultFolder;
                }
                if (folder != null)
                {
                    inFolder  = true;
                    readItems = (Messages)folder.Messages;
                    if (newMessages == 1)
                    {
                        MessageFilter filter = (MessageFilter)readItems.Filter;
                        filter.Unread = newMessages;
                    }
                    readItems.Sort(optional, optional);
                }
                else
                {
                    GXLogging.Error(log, "Could not open folder");
                    throw new GXMailException("Could not open folder", 5);
                }
            }
            else
            {
                GXLogging.Error(log, "Not logged in");
                throw new GXMailException("Not logged in", 2);
            }
        }
コード例 #10
0
        public short dfrgdate(out DateTime d, string fmt, string sep)
        {
            short retval = GX_ASCDEL_SUCCESS;

            d = DateTimeUtil.NullDate();
            string[] values = null;
            int      year = 0; int month = 0; int day = 0;

            if (_readStatus != FileIOStatus.DataReady)
            {
                GXLogging.Error(log, "Error ADF0004 o ADF0006");
                return(GX_ASCDEL_INVALIDSEQUENCE);
            }

            string fld = getNextFld(-1);

            try
            {
                values = fld.Split(sep[0]);

                for (int i = 0; i < 3; i++)
                {
                    int value = Convert.ToInt32(values[i]);
                    switch (fmt[i])
                    {
                    case 'y':
                        year = value;
                        break;

                    case 'm':
                        month = value;
                        break;

                    case 'd':
                        day = value;
                        break;

                    default:
                        return(GX_ASCDEL_BADFMTSTR);
                    }
                }

                if (month == 0 && day == 0 && year == 0)
                {
                    d = DateTimeUtil.NullDate();
                }
                else if (month < 1 || month > 12 || day < 1 || day > 31)
                {
                    retval = GX_ASCDEL_INVALIDDATE;
                    GXLogging.Error(log, "Error ADF0010");
                }
                else
                {
                    d = new DateTime(year, month, day);
                }
            }
            catch
            {
                retval = GX_ASCDEL_INVALIDFORMAT;
            }
            return(retval);
        }
コード例 #11
0
        private void ReadBody(MailReader reader, MailProperties partProps, String separator)
        {
            string contentType = partProps.GetKeyPrincipal("Content-Type");

            bool isTextPlain  = (string.Compare(contentType, "text/plain", true) == 0);
            bool isTextHtml   = (string.Compare(contentType, "text/html", true) == 0);
            bool isAttachment = (!isTextPlain && !isTextHtml) || AttachmentContentDisposition(partProps);

            string oldSeparator = reader.GetSeparator();

            reader.SetSeparator(separator);
            reader.SetTextPlain(isTextPlain);
            GXLogging.Debug(log, "isAttachment:" + isAttachment + " isTextHTML:" + isTextHtml + " istextplain:" + isTextPlain);
            MimeDecoder decoder = GetDecoder(partProps.GetField("Content-Transfer-Encoding"));

            if (isAttachment)
            {
                string outname = string.Empty;
                try
                {
                    Stream output;
                    if (this.DownloadAttachments)
                    {
                        string cid = GetAttachmentContentId(partProps);

                        string fileName = qpDecoder.DecodeHeader(RemoveQuotes(partProps.GetKeyProperty("Content-Disposition", "filename")));
                        if (string.IsNullOrEmpty(fileName))
                        {
                            fileName = RemoveQuotes(partProps.GetKeyProperty("Content-Type", "name"));
                        }

                        bool inlineAttachment = partProps.GetKeyPrincipal("Content-Disposition").StartsWith("inline");
                        if (inlineAttachment && !string.IsNullOrEmpty(cid))
                        {
                            fileName         = String.Format("{0}_{1}", cid, fileName);
                            outname          = GetFileName(attachmentsPath, fileName, contentType);
                            this.messageHtml = this.messageHtml.Replace("cid:" + cid, outname);
                        }
                        else
                        {
                            outname = GetFileName(attachmentsPath, fileName, contentType);
                        }

                        attachments += outname + ";";

                        if (!Directory.Exists(attachmentsPath))
                        {
                            Directory.CreateDirectory(attachmentsPath);
                        }
                        output = new FileStream(attachmentsPath + outname, FileMode.Create);
                    }
                    else
                    {
                        output = new DummyStream();
                    }
                    try
                    {
                        decoder.DecodeFile(reader, output, runner);
                    }
                    catch (Exception e)
                    {
                        GXLogging.Error(log, "ReadBody error", e);
                        throw e;
                    }
                    finally
                    {
                        output.Close();
                    }
                }
                catch (DirectoryNotFoundException dex)
                {
                    GXLogging.Error(log, "Error with attachments, attachment path:" + attachmentsPath + outname, dex);
                    throw new CouldNotSaveAttachmentException(dex);
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null)
                    {
                        ex = ex.InnerException;
                    }
                    GXLogging.Error(log, "Error with attachments, attachment path:" + attachmentsPath + outname, ex);
                    throw new InvalidAttachmentException(ex);
                }
            }
            else
            {
                try
                {
                    TextWriter output = new StringWriter();
                    try
                    {
                        decoder.DecodeText(reader, output, runner);
                        if (isTextPlain)
                        {
                            messageText.Append(((StringWriter)output).GetStringBuilder().ToString());
                        }
                        else if (isTextHtml)
                        {
                            messageHtml.Append(((StringWriter)output).GetStringBuilder().ToString());
                        }
                    }
                    catch (Exception e)
                    {
                        GXLogging.Error(log, "ReadBody error", e);
                        throw e;
                    }
                    finally
                    {
                        output.Close();
                    }
                }
                catch (Exception ex1)
                {
                    if (ex1.InnerException != null)
                    {
                        ex1 = ex1.InnerException;
                    }
                    GXLogging.Error(log, "ReadBody error", ex1);
                    throw new InvalidMessageException(ex1);
                }
            }
            reader.SetSeparator(oldSeparator);
        }
コード例 #12
0
        public void Receive(GXPOP3Session sessionInfo, GXMailMessage gxmessage)
        {
            if (client == null)
            {
                LogError("Login Error", "Must login", MailConstants.MAIL_CantLogin);
                return;
            }

            if (lastReadMessage == count)
            {
                LogDebug("No messages to receive", "No messages to receive", MailConstants.MAIL_NoMessages);
                return;
            }
            try {
                if (count > lastReadMessage)
                {
                    Message m = null;
                    try
                    {
                        m = client.GetMessage(++lastReadMessage);
                    }
                    catch (Exception e)
                    {
                        LogError("Receive message error", e.Message, MailConstants.MAIL_ServerRepliedErr, e);
                    }

                    if (m != null)
                    {
                        MailMessage msg;
                        try
                        {
                            msg = m.ToMailMessage();
                        }
                        catch (ArgumentException ae)
                        {
                            GXLogging.Error(log, "Receive message error " + ae.Message + " subject:" + m.Headers.Subject, ae);
                            PropertyInfo subjectProp = m.Headers.GetType().GetProperty("Subject");
                            string       subject     = m.Headers.Subject;
                            if (HasCROrLF(subject))
                            {
                                subjectProp.SetValue(m.Headers, subject.Replace('\r', ' ').Replace('\n', ' '));
                                GXLogging.Warn(log, "Replaced CR and LF in subject " + m.Headers.Subject);
                            }
                            msg = m.ToMailMessage();
                        }
                        using (msg)
                        {
                            gxmessage.From = new GXMailRecipient(msg.From.DisplayName, msg.From.Address);
                            SetRecipient(gxmessage.To, msg.To);
                            SetRecipient(gxmessage.CC, msg.CC);
                            gxmessage.Subject = msg.Subject;
                            if (msg.IsBodyHtml)
                            {
                                gxmessage.HTMLText = msg.Body;
                                MessagePart plainText = m.FindFirstPlainTextVersion();
                                if (plainText != null)
                                {
                                    gxmessage.Text += plainText.GetBodyAsText();
                                }
                            }
                            else
                            {
                                gxmessage.Text = msg.Body;
                            }
                            if (msg.ReplyToList != null && msg.ReplyToList.Count > 0)
                            {
                                SetRecipient(gxmessage.ReplyTo, msg.ReplyToList);
                            }

                            gxmessage.DateSent = m.Headers.DateSent;
                            if (gxmessage.DateSent.Kind == DateTimeKind.Utc && GeneXus.Application.GxContext.Current != null)
                            {
                                gxmessage.DateSent = DateTimeUtil.FromTimeZone(m.Headers.DateSent, "Etc/UTC", GeneXus.Application.GxContext.Current);
                            }
                            gxmessage.DateReceived = GeneXus.Mail.Internals.Pop3.MailMessage.GetMessageDate(m.Headers.Date);
                            AddHeader(gxmessage, "DispositionNotificationTo", m.Headers.DispositionNotificationTo.ToString());
                            ProcessMailAttachments(gxmessage, m.FindAllAttachments());
                        }
                    }
                }
            }catch (Exception e)
            {
                LogError("Receive message error", e.Message, MailConstants.MAIL_ServerRepliedErr, e);
            }
        }