Exemplo n.º 1
0
        public static string get_comment(SharpMimeMessage mime_message)
        {
            string comment = "";

            if (mime_message.Header.ContentType.ToLower().IndexOf("text/plain") > -1 &&
                !MyMime.is_attachment(mime_message))
            {
                comment = mime_message.BodyDecoded;
            }
            else
            {
                comment = MyMime.extract_comment_text_from_email(mime_message, "text/plain");
                if (comment == null)
                {
                    comment = MyMime.extract_comment_text_from_email(mime_message, "text/html");
                }

                if (comment == null)
                {
                    comment = "NO PLAIN TEXT MESSAGE BODY FOUND";
                }
            }

            return(comment);
        }
Exemplo n.º 2
0
        public static string get_comment(SharpMimeMessage mime_message)
        {
            string comment = MyMime.extract_comment_text_from_email(mime_message, "text/plain");

            if (comment == null)
            {
                comment = MyMime.extract_comment_text_from_email(mime_message, "text/html");
            }

            if (comment == null)
            {
                comment = "NO PLAIN TEXT MESSAGE BODY FOUND";
            }

            return(comment);
        }
Exemplo n.º 3
0
        public static Security get_synthesized_security(SharpMimeMessage mime_message, string from_addr, string username)
        {
            // Get the btnet user, which might actually be a user that corresonds with the email sender, not the username above
            DataRow dr = MyMime.get_user_datarow_maybe_using_from_addr(mime_message, from_addr, username);

            // simulate a user having logged in, for downstream code
            Security security = new Security();

            security.context       = System.Web.HttpContext.Current;
            security.user.username = username;
            security.user.usid     = (int)dr["us_id"];
            security.user.is_admin = Convert.ToBoolean(dr["us_admin"]);
            security.user.org      = (int)dr["us_org"];
            security.user.other_orgs_permission_level = (int)dr["og_other_orgs_permission_level"];
            security.user.forced_project = (int)dr["us_forced_project"];

            return(security);
        }
Exemplo n.º 4
0
        public static string get_comment(SharpMimeMessage mime_message)
        {
            string comment = MyMime.extract_comment_text_from_email(mime_message, "text/plain");

            // Corey says... commenting this out 2014-04-03.  I simply can't remember what I was thinking here.
            // Why would I copy the HTML version of the email into the comment text?

            //if (comment == null)
            //{
            //    comment = MyMime.extract_comment_text_from_email(mime_message, "text/html");
            //}

            if (comment == null)
            {
                comment = "NO PLAIN TEXT MESSAGE BODY FOUND";
            }

            return(comment);
        }
Exemplo n.º 5
0
        ///////////////////////////////////////////////////////////////////////
        public static string get_headers_for_comment(SharpMimeMessage mime_message)
        {
            string headers = "";

            if (mime_message.Header.Subject != null && mime_message.Header.Subject != "")
            {
                headers = "Subject: " + MyMime.get_subject(mime_message) + "\n";
            }

            if (mime_message.Header.To != null && mime_message.Header.To != "")
            {
                headers += "To: " + MyMime.get_to(mime_message) + "\n";
            }

            if (mime_message.Header.Cc != null && mime_message.Header.Cc != "")
            {
                headers += "Cc: " + MyMime.get_cc(mime_message) + "\n";
            }

            return(headers);
        }
Exemplo n.º 6
0
        //*************************************************************

        public static bool fetch_messages(string project_user, string project_password, int projectid)
        {
            // experimental, under construction

            POP3Client.POP3client client = new POP3Client.POP3client(Pop3ReadInputStreamCharByChar);

            string[] SubjectCannotContainStrings = Util.rePipes.Split(Pop3SubjectCannotContain);
            string[] FromCannotContainStrings    = Util.rePipes.Split(Pop3FromCannotContain);

            //try
            {
                System.Data.DataRow defaults = Bug.get_bug_defaults();

                //int projectid = (int)defaults["pj"];
                int categoryid = (int)defaults["ct"];
                int priorityid = (int)defaults["pr"];
                int statusid   = (int)defaults["st"];
                int udfid      = (int)defaults["udf"];

                Util.write_to_log("pop3:" + client.connect(Pop3Server, Pop3Port, Pop3UseSSL));

                Util.write_to_log("pop3:sending POP3 command USER");
                Util.write_to_log("pop3:" + client.USER(project_user));

                Util.write_to_log("pop3:sending POP3 command PASS");
                Util.write_to_log("pop3:" + client.PASS(project_password));

                Util.write_to_log("pop3:sending POP3 command STAT");
                Util.write_to_log("pop3:" + client.STAT());

                Util.write_to_log("pop3:sending POP3 command LIST");
                string list;
                list = client.LIST();
                Util.write_to_log("pop3:list follows:");
                Util.write_to_log(list);

                string[] messages = null;
                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("\r\n");
                messages = regex.Split(list);

                int end = messages.Length - 1;

                // loop through the messages
                for (int i = 1; i < end; i++)
                {
                    int    space_pos          = messages[i].IndexOf(" ");
                    int    message_number     = Convert.ToInt32(messages[i].Substring(0, space_pos));
                    string message_raw_string = client.RETR(message_number);

                    if (Pop3WriteRawMessagesToLog)
                    {
                        Util.write_to_log("raw email message:");
                        Util.write_to_log(message_raw_string);
                    }

                    SharpMimeMessage mime_message = MyMime.get_sharp_mime_message(message_raw_string);

                    string from_addr = MyMime.get_from_addr(mime_message);
                    string subject   = MyMime.get_subject(mime_message);


                    if (Pop3SubjectMustContain != "" && subject.IndexOf(Pop3SubjectMustContain) < 0)
                    {
                        Util.write_to_log("skipping because subject does not contain: " + Pop3SubjectMustContain);
                        continue;
                    }

                    bool bSkip = false;

                    for (int k = 0; k < SubjectCannotContainStrings.Length; k++)
                    {
                        if (SubjectCannotContainStrings[k] != "")
                        {
                            if (subject.IndexOf(SubjectCannotContainStrings[k]) >= 0)
                            {
                                Util.write_to_log("skipping because subject cannot contain: " + SubjectCannotContainStrings[k]);
                                bSkip = true;
                                break;  // done checking, skip this message
                            }
                        }
                    }

                    if (bSkip)
                    {
                        continue;
                    }

                    if (Pop3FromMustContain != "" && from_addr.IndexOf(Pop3FromMustContain) < 0)
                    {
                        Util.write_to_log("skipping because from does not contain: " + Pop3FromMustContain);
                        continue; // that is, skip to next message
                    }

                    for (int k = 0; k < FromCannotContainStrings.Length; k++)
                    {
                        if (FromCannotContainStrings[k] != "")
                        {
                            if (from_addr.IndexOf(FromCannotContainStrings[k]) >= 0)
                            {
                                Util.write_to_log("skipping because from cannot contain: " + FromCannotContainStrings[k]);
                                bSkip = true;
                                break; // done checking, skip this message
                            }
                        }
                    }

                    if (bSkip)
                    {
                        continue;
                    }


                    int    bugid   = MyMime.get_bugid_from_subject(ref subject);
                    string cc      = MyMime.get_cc(mime_message);
                    string comment = MyMime.get_comment(mime_message);
                    string headers = MyMime.get_headers_for_comment(mime_message);
                    if (headers != "")
                    {
                        comment = headers + "\n" + comment;
                    }

                    Security security = MyMime.get_synthesized_security(mime_message, from_addr, Pop3ServiceUsername);
                    int      orgid    = security.user.org;

                    if (bugid == 0)
                    {
                        if (security.user.forced_project != 0)
                        {
                            projectid = security.user.forced_project;
                        }

                        if (subject.Length > 200)
                        {
                            subject = subject.Substring(0, 200);
                        }

                        Bug.NewIds new_ids = Bug.insert_bug(
                            subject,
                            security,
                            "", // tags
                            projectid,
                            orgid,
                            categoryid,
                            priorityid,
                            statusid,
                            0,          // assignedid,
                            udfid,
                            "", "", "", // project specific dropdown values
                            comment,
                            comment,
                            from_addr,
                            cc,
                            "text/plain",
                            false, // internal only
                            null,  // custom columns
                            false);

                        MyMime.add_attachments(mime_message, new_ids.bugid, new_ids.postid, security);

                        // your customizations
                        Bug.apply_post_insert_rules(new_ids.bugid);

                        Bug.send_notifications(Bug.INSERT, new_ids.bugid, security);
                        WhatsNew.add_news(new_ids.bugid, subject, "added", security);

                        MyPop3.auto_reply(new_ids.bugid, from_addr, subject, projectid);
                    }
                    else // update existing
                    {
                        string StatusResultingFromIncomingEmail = Util.get_setting("StatusResultingFromIncomingEmail", "0");

                        string sql = "";

                        if (StatusResultingFromIncomingEmail != "0")
                        {
                            sql = @"update bugs
				                set bg_status = $st
				                where bg_id = $bg
				                "                ;

                            sql = sql.Replace("$st", StatusResultingFromIncomingEmail);
                        }

                        sql += "select bg_short_desc from bugs where bg_id = $bg";
                        sql  = sql.Replace("$bg", Convert.ToString(bugid));
                        DataRow dr2 = DbUtil.get_datarow(sql);

                        // Add a comment to existing bug.
                        int postid = Bug.insert_comment(
                            bugid,
                            security.user.usid, // (int) dr["us_id"],
                            comment,
                            comment,
                            from_addr,
                            cc,
                            "text/plain",
                            false); // internal only

                        MyMime.add_attachments(mime_message, bugid, postid, security);
                        Bug.send_notifications(Bug.UPDATE, bugid, security);
                        WhatsNew.add_news(bugid, (string)dr2["bg_short_desc"], "updated", security);
                    }

                    if (Pop3DeleteMessagesOnServer)
                    {
                        Util.write_to_log("sending POP3 command DELE");
                        Util.write_to_log(client.DELE(message_number));
                    }
                }
            }
            //catch (Exception ex)
            //{
            //    Util.write_to_log("pop3:exception in fetch_messages: " + ex.Message);
            //    error_count++;
            //    if (error_count > Pop3TotalErrorsAllowed)
            //    {
            //        return false;
            //    }
            //}


            Util.write_to_log("pop3:quit");
            Util.write_to_log("pop3:" + client.QUIT());
            return(true);
        }