Home Page
make a choice: Photoshop 7 or Photoshop CS/CS 2
Uncle Gugl - a giant
How to name a Web-site?
Spam - a problem of a century
register_globals=oN? You in danger!
Gathering of statistics on PHP
Transformation XML + XSLT with help Sablotron
Patterns of documents and Perl
The signature or avatars on pkhp
Privatnost` in the Internet
Use of the module for job with patterns
Alternative MIME:: Parser and Email:: Simple
Job with sessions in perl
Creation of dynamic forms with help JavaScript
*.JS when to be loaded you think?
Module CGI.pm
XML in 10 theses
Platformo-independent dynamic site - a myth or a reality?
Something about WAP
 

Alternative MIME:: Parser and Email:: Simple

MIME alterations


Somebody reflected sometime on that, what for in MIME have thought up complex  structures of the data?


- a


- b


- b-


- c


- c-


- a


- a-


(it that you knew about what I speak)


In one of FAQ such idea rolls, that the pier kantora Netscape was strongly complicated with a life when has made possible{probable} introduction in letters of this standard MIME, i.e. it is a lot of parts in one.


Actually problemma has not strongly changed since those times, and now I yet did not meet conceptually correct programs podkhodjahhhhikh to analysis of structure of letters so all programs give the CLUMSY interface to complex  letters.


And in fact uneasy structures appear only at a stage when we to the letter shall attach atach.


And srednestaticheskoe the complex  letter are two parts the text and html. If to them to add attach the problem  of analysis becomes already unusual.


How approaches to business MIME:: Parser?


In the documentation it is mentioned, what is it means is capable to work with any complex  structures, however edinorazovyj analysis of the letter for some reason parsit only the first level of the letter (on our example in result we shall receive parts - a, thus the first part - a will contain nerasparsennye parts - c and - b.


Whether it turns out that we need to find out itself is necessary parsit` further.


Me as developer of a correct - conceptual nucleus and as further the applied programmer using the given nucleus - such rasklad in any way does not arrange.


I want that I have simply called function and that I have received the list of contents of the letter as object or as complex  structure or something else, is unimportant that but whence it is possible to get any given letters, not addressing recursively each time to a nucleus as soon as I shall find out next nerasparsennuju a part.


Module Email:: Simple has approached to problemme absolutely similarly, and actually all the most known obrabotchiki MIME. Email:: Simple the truth has those priemuhhestva, that the code parsera is essentially minimal, in comparison with cow flat cake MIME:: Parser. However the First has not solved problemmu a recursive call, and uniform structure for all parts of the letter.


It is possible to say - well and it is correct, it and is not necessary to us, in fact letters come in more less stipulated standards so atachi it is possible to pull out easily foreknowing structure and addressing at once to the necessary parts.


Deep marasm - I shall say to you. Time have entered the universal standard, and necessary universal processing is correct.


I have thought that it would be necessary to throw itself any plain module, which scalar in structure would plant without pontov superfluous. And how?


To a head there has come beautiful algorithm, beautiful structure.


And I already was started to write, how have suddenly run on problemmu:


It is necessary to create complex  structure comparable with structure of the letter.


Objective model Perl I did not begin to use because neznaju her .


And all should be fastened on complex  structures.


Besides thanks God I more than once wrote pereborhhiki complex  structures, therefore vprincipe it not problemma, but all taki a code perebora structures - business not fast, something is necessary more beautiful.


And besides conceptually correct.


And after one hour of painful reflections per a head there has come a perfect idea what in fact as a matter of fact not so the structure of letters as simple access to contents is important. The decision has emerged by itself.. All structure of the letter should be opened in linear structure, access to each part of the letter is possible{probable} through a simple cycle, without use rekursii. And If there will be a necessity for the analysis all the same the structure then it is possible to resort to the analysis of sequences of parts.


This idea has been based universal parsera MIME which enters in sosotav ret WebOS, and is essentially free from modules of the given project, as well as all sotal`nye modules of the given project are independent.


In aggregate with other modules the project now has accepted one more direction parsing MIME.


Well and plus that is that as a result of job of function of processing of the letter one complex  linear structure which further can be completely all sozranena as one recording in database SUBD ret WebOS which puts under itself one of the major and important problems{tasks} is created: storage of complex  structures (the structure of any complexity can be written down as the unique recording in blogovoj models ret bases.


To become ridiculously when having seen at module MIME:: Parser then you look at the following piece of a code which I have written in some prisjadov:



sub ParseEmail


{


   ($msg) = _;


   $ *main_structure =-1;


   $main_structure [0] = ";


   push @stack, $msg;


   * start stack working


   while (scalar @stack> 0)


   {


      $msg_process=pop @stack;


      $msg_process = ~ / (. *? ($ crlf)) \2 (. *)/sm;


      $head = $ 1;


      $body = $ 3;


      for (split / $crlf/, $head)


      {


         if (/^ ([^:] +):\s * (. *)/)


         {


            $pos = $ * main_structure;


            $main_structure [$pos] {$1} = $2;


}


}


      * found boundary Easiest way to get boundary in fucked MIME


      $head = ~/\s*boundary = "? ([^\s "] +) "?/sm;


      $boundary = $ 1;


      * has we a boundary?


      if (length $boundary> 4 and length $boundary <40)


      {


         * separate body to parts to stack


         $tempo =-1;


         @tempo=split (/-$boundary/, $body);


         my $o = $ * tempo;


         for (my $i=1; $i <$o; $i ++)


         {


             push @stack, $tempo [$i];


}


}


      else


      {


         * save bady to massive


         $pos ++;


         $main_structure [$pos] = $body;


}


}


}


The given piece parsit MIME which is passed him in line.


And from the letter of any complexity the complex  linear structure which it is possible to touch all in a cycle turns out!


Voohhem all as is written above.


That here is not present?


Here there are no code conversions, and for this purpose there are ready decisions.


Has arisen any problemma with parsing complex  parameters such as


Content-Type. Therefore for parameters of heading the unique algorithm operates.


Heading: the Text


Where the text can contain some parameters.


I here did not take into account it (not considering boundary)


In general a history with boundary oochen` strange and I in any way shall not understand this standard MIME, what for was to resolve in general boundary to write as a part of heading Content-Type and if on that went what for was to resolve before boundary to specify a symbol crlf. It turns out that all headings as headings begin exclusively with a new line, and here not the heading, and a piece from prediduhhego heading suddenly began since a new line, and guess where here the beginning boundary and where the beginning of heading. Has besides lead{Has besides carried out} the small analysis of letters.. Also are really used completely bezbashennye vrianty recordings boundary that in one line that in two so-called that without, and what symbols are used for the instruction{indication} boundary - and at all it is not necessary and to write.


The blessing of blanks did not see.


Therefore the way which is resulted here raschitan on that that in heading there will be a unique index on boundary, therefore observance of various rules for us is pereborom. For experts here already really it is necessary to take RFC and simply to write on it . My variant will work in most cases. And if something not so it is possible to change easily something, in fact the code is located on one leaf of format A4 in a readable kind. Study - nekhochu.


It is possible to say what is it one of the smallest variants of parsing mIME in view of complex  structures and creation of those.


On sim I finish lyrics.


Has come it is time to decode a body and headings and the everything else.\






© Web Development Company Conkurent, LLC 2007-2009. All rights reserved.