You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mime4j-dev@james.apache.org by Eric Charles <er...@apache.org> on 2011/05/16 11:47:59 UTC

JSON parsing in mynajs (was Re: Headless mail renderer)

Hi Tony,

Cool! Tks for this :)

Event if index.ejs gives some clues on how to run, it would be great to 
have a short README that explains how to use it (and how to call it from 
a Java main class).

Tks,
Eric


On 16/05/2011 04:45, Tony Zakula wrote:
> Hi Eric and all,
>
> I have posted some basic code for parsing emails using Mime4J and JavaScript at
>
> https://bitbucket.org/tzakula/javascript-email-bounce-processor
>
> Thanks.
>
> Tony Z
>
>
>
> On Thu, May 12, 2011 at 10:28 PM, Eric Charles<er...@apache.org>  wrote:
>> Hi Tony,
>>
>> We've got also the apache-extras [1] which is mercurial (hosted by google
>> for addons to apache projects).
>>
>> I was wondering if the parser can be used without the full myna server. I
>> mean, we simply need to parse mail, not to configure a full server with
>> users,... ([2]).
>>
>> Also, is the parser component packaged as a maven module to be easily used
>> as dependency somewhere else?
>>
>> Whatever the response to the 2 above questions, feel free to push it where
>> you like. I will look at it :)
>>
>> Tks,
>> - Eric
>>
>> [1] http://code.google.com/a/apache-extras.org/hosting/
>> [2] http://www.mynajs.org/site/article/MynaPermissionsAdministrator.ejs
>>
>>
>> On 13/05/2011 01:51, Tony Zakula wrote:
>>>
>>> Hi Eric,
>>>
>>> JavaScript is also extremely flexible.  With Rhino, you get the full
>>> power of Java plus a lot of flexibility.
>>>
>>> What is the preferred spot of release?  Github, Bitbuckit, or is there
>>> another?
>>>
>>> Tony
>>>
>>>
>>> On Thu, May 12, 2011 at 8:19 AM, Eric Charles<er...@apache.org>    wrote:
>>>>
>>>> Hi Tony,
>>>>
>>>> Javascript in james server would be a primeur.
>>>> But why not... there is more and more JS "on the other side" (thinking to
>>>> Node.js...). I'm using today Jackson to manipulate JSON in Java, but
>>>> Javascript has a more natural fit, so I understand why you choose it.
>>>>
>>>> We will start around end-May with MAILBOX-44, but there today no
>>>> discussions/decisions on the chosen format to persist mail.
>>>>
>>>> I would say "don't hurry, don't put pressure on you, and keep us updated
>>>> when you think to release it" :)
>>>>
>>>> Tks,
>>>> - Eric
>>>>
>>>> On 12/05/2011 14:35, Tony Zakula wrote:
>>>>>
>>>>> Hi Eric,
>>>>>
>>>>> I would be more than happy to release the code now even though it is
>>>>> not entirely finished if you are interested.  The parsing part is
>>>>> pretty good, and I am using it in a production project right now.  I
>>>>> am not sure it will fit your bill though as I am using it on a mail
>>>>> server to do message list bounce processing.  Although I write Java
>>>>> code for a living, I wanted to make it easy to modify this utility on
>>>>> a running server so I used an open source project I contribute to at
>>>>> Mynajs.org which is built on top of the Mozilla Rhino project.  I use
>>>>> Mime4J, but my code is written in JavaScript.
>>>>>
>>>>> I would be more than happy to release the code now if you are
>>>>> interested.
>>>>>
>>>>> Please let me know.
>>>>>
>>>>> Thanks!
>>>>>
>>>>> Tony
>>>>>
>>>>> On Wed, May 11, 2011 at 11:21 PM, Eric Charles<er...@apache.org>
>>>>>   wrote:
>>>>>>
>>>>>> Hi Tony,
>>>>>>
>>>>>> We are starting to work on MAILBOX-44 "Design and implement a
>>>>>> distributed
>>>>>> mailbox using Hadoop" [1]
>>>>>>
>>>>>> We will need to store the mail in hadoop and the JSON format (in avro
>>>>>> file)
>>>>>> may be a option.
>>>>>>
>>>>>> You said you are "still polishing for release" your JSON transformer.
>>>>>> Have you got any plan to release it in opensource so we could use it ?
>>>>>>
>>>>>> Tks,
>>>>>> Eric
>>>>>>
>>>>>> [1] https://issues.apache.org/jira/browse/MAILBOX-44
>>>>>>
>>>>>>
>>>>>> On 10/05/2011 10:00, Robert Burrell Donkin wrote:
>>>>>>>
>>>>>>> On Sun, May 8, 2011 at 2:44 PM, Tony Zakula<to...@gmail.com>
>>>>>>>   wrote:
>>>>>>>>
>>>>>>>> Not sure on where the project leaders want to go,
>>>>>>>
>>>>>>> Projects are community led here at Apache (see eg [1][2][3][4]). If
>>>>>>> there's development interest from the community and it's in scope for
>>>>>>> the project, then that's a direction the code will move in.
>>>>>>>
>>>>>>>> but I think being
>>>>>>>> able to store messages in different formats to be able to plugin to
>>>>>>>> systems would be great.  Instead of each person writing their own
>>>>>>>> parser, most people would just plugin the larger piece to their
>>>>>>>> system
>>>>>>>> and start there.
>>>>>>>
>>>>>>> +1
>>>>>>>
>>>>>>> This vision seems to fit with the work over at Tika [5] and Lucene
>>>>>>> [6].
>>>>>>>
>>>>>>>> I did not see where you specified what you are thinking about for
>>>>>>>> summer.  Is that a link somewhere yet?
>>>>>>>
>>>>>>> The mailing lists (see [7] and eg [8]) are the primary tools we use
>>>>>>> here at Apache. Stuff only tends to get written down later, if at all.
>>>>>>> We've been throwing ideas around on the lists, hoping that people
>>>>>>> might pick some of them up and run with them ;-)
>>>>>>>
>>>>>>> Robert
>>>>>>>
>>>>>>> [1] http://www.apache.org/foundation/how-it-works.html
>>>>>>> [2] http://www.apache.org/foundation/getinvolved.html
>>>>>>> [3] http://jakarta.apache.org/site/contributing.html
>>>>>>> [4] http://www.apache.org/dev/contributors.html
>>>>>>> [5] http://tika.apache.org/
>>>>>>> [6] http://lucene.apache.org/
>>>>>>> [7] http://www.apache.org/dev/#mail
>>>>>>> [8] http://www.apache.org/dev/contrib-email-tips.html
>>>>>>
>>>>>>
>>>>
>>>>
>>
>>


Re: JSON parsing in mynajs (was Re: Headless mail renderer)

Posted by Tony Zakula <to...@gmail.com>.
Hi Eric,

I will put it on my list, but the main work is being done in - [1]

The method probably for your purposes to look at is at the bottom of
that file and is:

var parseMessage = function parse_message(fileName) {
  // This function parses the message and gets it back in JSON
  var object = null;
  var fis = new Myna.File(fileName).getInputStream();
  //Create message with stream from file
  try {
    var mimeMsg = new org.apache.james.mime4j.message.Message(fis);
  }
  catch (e) {
    // if error it is from parser, just delete message.
    //Myna.println("Mime4J error parsing message")
  }
  object = files.createEntityNode(mimeMsg);
  fis.close();
  return object;
}

The create entity node located at the following link is really the
recursive function that does the parsing - [2]

Things are setup through index.ejs to be able to be called from an
http connection as Myna is deployed as a Java webapp.  To call from a
Java main method, we would need to customize Myna or create a Rhino
host object as Mark described [3].

Tony Zakula
Direct Line (906) 364-8082

[1] https://bitbucket.org/tzakula/javascript-email-bounce-processor/src/65b933d28c1f/bounceProcessor/processBounces.sjs
[2] https://bitbucket.org/tzakula/javascript-email-bounce-processor/src/65b933d28c1f/bounceProcessor/createEntityNode.sjs
[3] https://groups.google.com/forum/#!topic/mynajs-general/UnMTvxHNE



On Mon, May 16, 2011 at 4:47 AM, Eric Charles <er...@apache.org> wrote:
> Hi Tony,
>
> Cool! Tks for this :)
>
> Event if index.ejs gives some clues on how to run, it would be great to have
> a short README that explains how to use it (and how to call it from a Java
> main class).
>
> Tks,
> Eric
>
>
> On 16/05/2011 04:45, Tony Zakula wrote:
>>
>> Hi Eric and all,
>>
>> I have posted some basic code for parsing emails using Mime4J and
>> JavaScript at
>>
>> https://bitbucket.org/tzakula/javascript-email-bounce-processor
>>
>> Thanks.
>>
>> Tony Z
>>
>>
>>
>> On Thu, May 12, 2011 at 10:28 PM, Eric Charles<er...@apache.org>  wrote:
>>>
>>> Hi Tony,
>>>
>>> We've got also the apache-extras [1] which is mercurial (hosted by google
>>> for addons to apache projects).
>>>
>>> I was wondering if the parser can be used without the full myna server. I
>>> mean, we simply need to parse mail, not to configure a full server with
>>> users,... ([2]).
>>>
>>> Also, is the parser component packaged as a maven module to be easily
>>> used
>>> as dependency somewhere else?
>>>
>>> Whatever the response to the 2 above questions, feel free to push it
>>> where
>>> you like. I will look at it :)
>>>
>>> Tks,
>>> - Eric
>>>
>>> [1] http://code.google.com/a/apache-extras.org/hosting/
>>> [2] http://www.mynajs.org/site/article/MynaPermissionsAdministrator.ejs
>>>
>>>
>>> On 13/05/2011 01:51, Tony Zakula wrote:
>>>>
>>>> Hi Eric,
>>>>
>>>> JavaScript is also extremely flexible.  With Rhino, you get the full
>>>> power of Java plus a lot of flexibility.
>>>>
>>>> What is the preferred spot of release?  Github, Bitbuckit, or is there
>>>> another?
>>>>
>>>> Tony
>>>>
>>>>
>>>> On Thu, May 12, 2011 at 8:19 AM, Eric Charles<er...@apache.org>    wrote:
>>>>>
>>>>> Hi Tony,
>>>>>
>>>>> Javascript in james server would be a primeur.
>>>>> But why not... there is more and more JS "on the other side" (thinking
>>>>> to
>>>>> Node.js...). I'm using today Jackson to manipulate JSON in Java, but
>>>>> Javascript has a more natural fit, so I understand why you choose it.
>>>>>
>>>>> We will start around end-May with MAILBOX-44, but there today no
>>>>> discussions/decisions on the chosen format to persist mail.
>>>>>
>>>>> I would say "don't hurry, don't put pressure on you, and keep us
>>>>> updated
>>>>> when you think to release it" :)
>>>>>
>>>>> Tks,
>>>>> - Eric
>>>>>
>>>>> On 12/05/2011 14:35, Tony Zakula wrote:
>>>>>>
>>>>>> Hi Eric,
>>>>>>
>>>>>> I would be more than happy to release the code now even though it is
>>>>>> not entirely finished if you are interested.  The parsing part is
>>>>>> pretty good, and I am using it in a production project right now.  I
>>>>>> am not sure it will fit your bill though as I am using it on a mail
>>>>>> server to do message list bounce processing.  Although I write Java
>>>>>> code for a living, I wanted to make it easy to modify this utility on
>>>>>> a running server so I used an open source project I contribute to at
>>>>>> Mynajs.org which is built on top of the Mozilla Rhino project.  I use
>>>>>> Mime4J, but my code is written in JavaScript.
>>>>>>
>>>>>> I would be more than happy to release the code now if you are
>>>>>> interested.
>>>>>>
>>>>>> Please let me know.
>>>>>>
>>>>>> Thanks!
>>>>>>
>>>>>> Tony
>>>>>>
>>>>>> On Wed, May 11, 2011 at 11:21 PM, Eric Charles<er...@apache.org>
>>>>>>  wrote:
>>>>>>>
>>>>>>> Hi Tony,
>>>>>>>
>>>>>>> We are starting to work on MAILBOX-44 "Design and implement a
>>>>>>> distributed
>>>>>>> mailbox using Hadoop" [1]
>>>>>>>
>>>>>>> We will need to store the mail in hadoop and the JSON format (in avro
>>>>>>> file)
>>>>>>> may be a option.
>>>>>>>
>>>>>>> You said you are "still polishing for release" your JSON transformer.
>>>>>>> Have you got any plan to release it in opensource so we could use it
>>>>>>> ?
>>>>>>>
>>>>>>> Tks,
>>>>>>> Eric
>>>>>>>
>>>>>>> [1] https://issues.apache.org/jira/browse/MAILBOX-44
>>>>>>>
>>>>>>>
>>>>>>> On 10/05/2011 10:00, Robert Burrell Donkin wrote:
>>>>>>>>
>>>>>>>> On Sun, May 8, 2011 at 2:44 PM, Tony Zakula<to...@gmail.com>
>>>>>>>>  wrote:
>>>>>>>>>
>>>>>>>>> Not sure on where the project leaders want to go,
>>>>>>>>
>>>>>>>> Projects are community led here at Apache (see eg [1][2][3][4]). If
>>>>>>>> there's development interest from the community and it's in scope
>>>>>>>> for
>>>>>>>> the project, then that's a direction the code will move in.
>>>>>>>>
>>>>>>>>> but I think being
>>>>>>>>> able to store messages in different formats to be able to plugin to
>>>>>>>>> systems would be great.  Instead of each person writing their own
>>>>>>>>> parser, most people would just plugin the larger piece to their
>>>>>>>>> system
>>>>>>>>> and start there.
>>>>>>>>
>>>>>>>> +1
>>>>>>>>
>>>>>>>> This vision seems to fit with the work over at Tika [5] and Lucene
>>>>>>>> [6].
>>>>>>>>
>>>>>>>>> I did not see where you specified what you are thinking about for
>>>>>>>>> summer.  Is that a link somewhere yet?
>>>>>>>>
>>>>>>>> The mailing lists (see [7] and eg [8]) are the primary tools we use
>>>>>>>> here at Apache. Stuff only tends to get written down later, if at
>>>>>>>> all.
>>>>>>>> We've been throwing ideas around on the lists, hoping that people
>>>>>>>> might pick some of them up and run with them ;-)
>>>>>>>>
>>>>>>>> Robert
>>>>>>>>
>>>>>>>> [1] http://www.apache.org/foundation/how-it-works.html
>>>>>>>> [2] http://www.apache.org/foundation/getinvolved.html
>>>>>>>> [3] http://jakarta.apache.org/site/contributing.html
>>>>>>>> [4] http://www.apache.org/dev/contributors.html
>>>>>>>> [5] http://tika.apache.org/
>>>>>>>> [6] http://lucene.apache.org/
>>>>>>>> [7] http://www.apache.org/dev/#mail
>>>>>>>> [8] http://www.apache.org/dev/contrib-email-tips.html
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>
>>>
>
>