Issue Tracker

Aveam nevoie de un tracker de issue – pentru ca incepusem sa am prea multe cereri de modificare si nu ma mai descurcam. De fapt, la o a doua vedere, nu erau atit de multe cereri, cit detalii ale lor.

Am cerut pareri pe RONUA – dar ceea ce mi s-a oferit de acolo era pe bani (ma rog, OnTime se pare ca are oferte speciale..). Iar in criza actuala sa cer bani de la servici ca eu nu ma mai descurc suna cam prost…

Dupa ce am citit de mai multe , m-am decis pentru BugTracker.NET. Am avut doua probleme : Integrarea cu Active Directory – din fericire Web.Config este destul de clar scris – si trimiterea emailurilor. Nu vroiam sa configurez SMTP – ci doar sa isi ia setarile din Web.Config de forma:

<system.net>
        <mailSettings>
            <smtp>
                <network host="xxxx" port="25"/>
            </smtp>
        </mailSettings>
    </system.net>

Din nefericire el lucra cu System.Web.Mail – asta pentru ca ,zicea el, noul System.NET.Mail nu suporta SSL.

In fine – nu aveam nevoie de SSL –asa ca am muncit sa il transform – si am modificat pe ici, pe colo, prin partile esentiale email.cs:

/*
Copyright 2002-2008 Corey Trager
Distributed under the terms of the GNU General Public License
*/

using System;
using System.Collections;
using System.IO;
using System.Text;

// disable System.Net.Mail warnings
#pragma warning disable 618

namespace btnet
{

    public class Email {
        ///////////////////////////////////////////////////////////////////////
        public static string send_email( // 5 args
            string to,
            string from,
            string cc,
            string subject,
            string body)
        {
            return send_email(
                to,
                from,
                cc,
                subject,
                body,
                false,
                System.Net.Mail.MailPriority.Normal,
                null,
                false);
        }

        ///////////////////////////////////////////////////////////////////////
        public static string send_email( // 6 args
            string to,
            string from,
            string cc,
            string subject,
            string body,
            bool isbodyhtml)
        {
            return send_email(
                to,
                from,
                cc,
                subject,
                body,
                isbodyhtml,
                System.Net.Mail.MailPriority.Normal,
                null,
                false);
        }

        ///////////////////////////////////////////////////////////////////////
        public static string send_email(
            string to,
            string from,
            string cc,
            string subject,
            string body,
            bool isbodyhtml,
            System.Net.Mail.MailPriority priority,
            int[] attachment_bpids,
            bool return_receipt)
        {
            ArrayList files_to_delete = new ArrayList();
            ArrayList directories_to_delete = new ArrayList();
            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(from, to);
            if (!string.IsNullOrEmpty(cc.Trim()))
            {
                msg.CC.Add(cc);
            }
            msg.Subject = subject;
            msg.Priority = priority;

            // This fixes a bug for a couple people, but make it configurable, just in case.
            if (Util.get_setting("BodyEncodingUTF8", "1") == "1")
            {
                msg.BodyEncoding = Encoding.UTF8;
            }

            if (return_receipt)
            {
                msg.Headers.Add("Disposition-Notification-To", from);
            }

            // workaround for a bug I don’t understand…
            if (Util.get_setting("SmtpForceReplaceOfBareLineFeeds", "0") == "1")
            {
                body = body.Replace("\n", "\r\n");
            }

            msg.Body = body;
            msg.IsBodyHtml = isbodyhtml;

            if (attachment_bpids != null && attachment_bpids.Length > 0)
            {

                string upload_folder =  btnet.Util.get_upload_folder();

                if (string.IsNullOrEmpty(upload_folder))
                {
                    upload_folder = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
                    Directory.CreateDirectory(upload_folder);
                    directories_to_delete.Add(upload_folder);
                }

                foreach (int attachment_bpid in attachment_bpids)
                {
                    byte[] buffer = new byte[16 * 1024];
                    string dest_path_and_filename;
                    Bug.BugPostAttachment bpa = Bug.get_bug_post_attachment(attachment_bpid);
                    using (bpa.content)
                    {
                        dest_path_and_filename = Path.Combine(upload_folder, bpa.file);
                        using (FileStream out_stream = new FileStream(
                            dest_path_and_filename,
                            FileMode.CreateNew,
                            FileAccess.Write,
                            FileShare.None))
                        {
                            int bytes_read =  bpa.content.Read(buffer, 0, buffer.Length);
                            while (bytes_read != 0)
                            {
                                out_stream.Write(buffer, 0, bytes_read);

                                bytes_read = bpa.content.Read(buffer, 0, buffer.Length);
                            }
                        }

                    }

                    System.Net.Mail.Attachment mail_attachment = new System.Net.Mail.Attachment(
                        dest_path_and_filename);
                    msg.Attachments.Add(mail_attachment);
                    files_to_delete.Add(dest_path_and_filename);
                }
            }

            try
            {
                // This fixes a bug for some people.  Not sure how it happens….
                msg.Body = msg.Body.Replace(Convert.ToChar(0), ‘ ‘).Trim();
                System.Net.Mail.SmtpClient s=new System.Net.Mail.SmtpClient();
                s.Send(msg);

                // We delete late here because testing showed that SmtpMail class
                // got confused when we deleted too soon.
                if (files_to_delete.Count > 0)
                {
                    foreach (string file in files_to_delete)
                    {
                        File.Delete(file);
                    }
                }

                if (directories_to_delete.Count > 0)
                {
                    foreach (string directory in directories_to_delete)
                    {
                        Directory.Delete(directory);
                    }
                }

                return "";
            }
            catch (Exception e)
            {
                Util.write_to_log("There was a problem sending email.   Check settings in Web.config.");
                Util.write_to_log("TO:" + to);
                Util.write_to_log("FROM:" + from);
                Util.write_to_log("SUBJECT:" + subject);
                Util.write_to_log(e.GetBaseException().Message.ToString());
                return (e.GetBaseException().Message);
            }

        }

    } // end Email

} // end namespace

Leave a Reply

Your email address will not be published. Required fields are marked *