archive-to-email.js

Go to the documentation of this file.
00001 /***
00002 archive-to-email: A TextMill module that parses emails out of an archive
00003 in mbox format.
00004 
00005 Copyright 2008 Michael Wojcik, wojcikm4@msu.edu.
00006 
00007 Note: "archive" should really be the more-specific "mbox".
00008 TODO: Fix that.
00009 ***/
00010 
00011 var archiveToEmail =
00012 {
00013    /* Module name for TM */
00014    name: "archiveToEmail",
00015 
00016    /***
00017    A TM Maker for creating a MultiText from an email. This method will
00018    be redefined by TM when the module is initialized with addModule.
00019    ***/
00020 
00021    MakeEmail: function(multiText, email)
00022    {
00023       logElement("p", "wrong MakeEmail called");
00024       return undefined;
00025    },
00026 
00027    /***
00028    A TM Taker for an mbox-format archive. It will find the individual
00029    messages in the archive and create new MultiTexts from them. (Note
00030    that it skips anything before the first "From " line, as messages must
00031    start with that line.)
00032    ***/
00033 
00034    TakeArchive: function(self, archive)
00035    {
00036       var msgs = archive.split(/\nFrom /);
00037       var i;
00038 
00039       for (i = 1; i < msgs.length; i++)
00040          self.MakeEmail(null, "From " + msgs[i]);
00041 
00042       return true;   /* tell caller we're done with this transform */
00043    },
00044 
00045    /***
00046    Start: looks for a div named "archive" and creates a MultiText from it if
00047    it exists. This lets the module bootstrap analysis if it's embedded in a
00048    page that contains an email archive.
00049    ***/
00050 
00051    Start: function()
00052    {
00053       TMLog(name + ": starting...");
00054       var archive = document.getElementById("archive");
00055       if (archive) archive = archive.innerHTML;
00056       // if (archive) this.TakeArchive(this, archive);
00057       if (archive)
00058       {
00059          /* Remove any HTML escapage */
00060          archive = archive.replace(/&lt;/g, "<");
00061          archive = archive.replace(/&gt;/g, ">");
00062          archive = archive.replace(/&amp;/g, "&");
00063 
00064          /* TODO: Refactor following into a TextMill.createMultiText */
00065          var multiText = new MultiText(this.name);
00066          var transform = new Transform(archive, "Archive", this.name);
00067          multiText.forms.Archive = [ transform ];
00068          multiText.form.Archive = transform;
00069          TextMill.stateChanged = true;
00070       }
00071       TMLog(name + ": started");
00072       return true;
00073    }
00074 };
00075 

Based on content generated using Doxygen