Thunderbird 60 add-on to replace blockquote with div in body

I’ve just finished writing a simple add-on for Thunderbird 60.9.0 that, upon sending an email, performs a global replace of all html blockquote tags for div tags in the email body.

I did this because I’m sick of the intending that occurs due to the use of blockquote tags. My emails have no indenting when I view them myself (due to me using the ReplyWithHeader add-on which hides the indenting) however all my friends/colleagues who use Outlook still see the indenting, and worse, when they reply to me the indenting reappears at my end (i.e. it is no longer hidden). It drives me nuts!

Anyway, my add-on is working well (first add-on I’ve written). The code I used is below. I just wanted to get some feedback from the community as to whether what I’ve done is the best and/or most sensible way to achieve this result.

Thank you all.

function send_event_handler(event) {

   var msg_compose_window = document.getElementById("msgcomposeWindow");
   var msg_type = msg_compose_window.getAttribute("msgtype");
   if (! (msg_type == nsIMsgCompDeliverMode.Now || msg_type == nsIMsgCompDeliverMode.Later)) return;

   try {
      var editor_type = GetCurrentEditorType();
      if (! (editor_type == "html" || editor_type == "htmlmail")) return;

      var editor = GetCurrentEditor();
      editor.beginTransaction();

      var body = editor.outputToString('text/html', 2);
      body = body.replace("<blockquote", "<div", "g");
      body = body.replace("blockquote>", "div>", "g");
      editor.rebuildDocumentFromSource(body);

      editor.endTransaction();

   } catch (e) {

      Components.utils.reportError(e);
      return false;
   }
}

window.addEventListener("compose-send-message", send_event_handler, true);

I discovered today I was using the wrong syntax on the string replace function. Subsequently, it was ignoring the “g” (global) modifier. I’ve updated to the code below.

function send_event_handler(event) {

	var msg_compose_window = document.getElementById("msgcomposeWindow");
	var msg_type = msg_compose_window.getAttribute("msgtype");
	if (! (msg_type == nsIMsgCompDeliverMode.Now || msg_type == nsIMsgCompDeliverMode.Later)) return;

	try {
		var editor_type = GetCurrentEditorType();
		if (! (editor_type == "html" || editor_type == "htmlmail")) return;

		var editor = GetCurrentEditor();
		editor.beginTransaction();

		var body = editor.outputToString('text/html', 2);
		body = body.replace(/<blockquote/gi, "<div");
		body = body.replace(/blockquote>/gi, "div>");
		editor.rebuildDocumentFromSource(body);

		editor.endTransaction();

	} catch (e) {

		Components.utils.reportError(e);
		return false;
	}
}

window.addEventListener("compose-send-message", send_event_handler, true);