///////////////////////////////////////////////////////////////////////
        int[] handle_attachments(int comment_id)
        {
            ArrayList attachments = new ArrayList();

            string filename = System.IO.Path.GetFileName(attached_file.PostedFile.FileName);

            if (filename != "")
            {
                //add attachment
                int max_upload_size = Convert.ToInt32(btnet.Util.get_setting("MaxUploadSize", "100000"));
                int content_length  = attached_file.PostedFile.ContentLength;
                if (content_length > max_upload_size)
                {
                    msg.InnerText = "File exceeds maximum allowed length of "
                                    + Convert.ToString(max_upload_size)
                                    + ".";
                    return(null);
                }

                if (content_length == 0)
                {
                    msg.InnerText = "No data was uploaded.";
                    return(null);
                }

                int bp_id = Bug.insert_post_attachment(
                    User.Identity,
                    Convert.ToInt32(bg_id.Value),
                    attached_file.PostedFile.InputStream,
                    content_length,
                    filename,
                    "email attachment",
                    attached_file.PostedFile.ContentType,
                    comment_id,
                    false, false);

                attachments.Add(bp_id);
            }

            //attachments to forward

            foreach (ListItem item_attachment in lstAttachments.Items)
            {
                if (item_attachment.Selected)
                {
                    int bp_id = Convert.ToInt32(item_attachment.Value);

                    Bug.insert_post_attachment_copy(User.Identity, Convert.ToInt32(bg_id.Value), bp_id, "email attachment", comment_id, false, false);
                    attachments.Add(bp_id);
                }
            }

            return((int[])attachments.ToArray(typeof(int)));
        }
Beispiel #2
0
        ///////////////////////////////////////////////////////////////////////

        public static void add_attachment(string filename, SharpMimeMessage part, int bugid, int parent_postid, Security security)
        {
            Util.write_to_log("attachment:" + filename);

            string missing_attachment_msg = "";

            int max_upload_size = Convert.ToInt32(Util.get_setting("MaxUploadSize", "100000"));

            if (part.Size > max_upload_size)
            {
                missing_attachment_msg = "ERROR: email attachment exceeds size limit.";
            }

            string       content_type = part.Header.TopLevelMediaType + "/" + part.Header.SubType;
            string       desc;
            MemoryStream attachmentStream = new MemoryStream();

            if (missing_attachment_msg == "")
            {
                desc = "email attachment";
            }
            else
            {
                desc = missing_attachment_msg;
            }

            part.DumpBody(attachmentStream);
            attachmentStream.Position = 0;
            Bug.insert_post_attachment(
                security,
                bugid,
                attachmentStream,
                (int)attachmentStream.Length,
                filename,
                desc,
                content_type,
                parent_postid,
                false,  // not hidden
                false); // don't send notifications
        }
        ///////////////////////////////////////////////////////////////////////
        void on_update()
        {
            var file = Request.Files["attached_file"];

            if (file == null)
            {
                file = Request.Files[0];
            }

            if (file == null)
            {
                write_msg("Please select file", false);
                return;
            }

            string filename = System.IO.Path.GetFileName(file.FileName);

            if (string.IsNullOrEmpty(filename))
            {
                write_msg("Please select file", false);
                return;
            }

            int max_upload_size = Convert.ToInt32(Util.get_setting("MaxUploadSize", "100000"));
            int content_length  = file.ContentLength;

            if (content_length > max_upload_size)
            {
                write_msg("File exceeds maximum allowed length of "
                          + Convert.ToString(max_upload_size)
                          + ".", false);
                return;
            }

            if (content_length == 0)
            {
                write_msg("No data was uploaded.", false);
                return;
            }

            bool good = false;

            try
            {
                Bug.insert_post_attachment(
                    User.Identity,
                    bugid,
                    file.InputStream,
                    content_length,
                    filename,
                    desc.Value,
                    file.ContentType,
                    -1, // parent
                    internal_only.Checked,
                    true);

                good = true;
            }
            catch (Exception ex)
            {
                write_msg("caught exception:" + ex.Message, false);
                return;
            }


            if (good)
            {
                write_msg(
                    filename
                    + " was successfully upload ("
                    + file.ContentType
                    + "), "
                    + Convert.ToString(content_length)
                    + " bytes"
                    , true);
            }
            else
            {
                // This should never happen....
                write_msg("Unexpected error with file upload.", false);
            }
        }