Changeset 5248 in project


Ignore:
Timestamp:
07/29/07 19:16:31 (13 years ago)
Author:
hans
Message:

version 1.3: factored out mime-get-attributes from mime-parse-content-type, added a missing backslash in mime-parse-version regexp

Location:
mime/trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • mime/trunk/mime.html

    r5246 r5248  
    11<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    2 <!-- Generated by eggdoc Revision: 1.17  -->
     2<!-- Generated by eggdoc Revision: 1.20  -->
    33<html>
    44<head>
     
    2626                    border-top: 1px solid #448;
    2727                    padding-left: 1em;
    28      }
     28                    margin-bottom: 1.2em;
     29     }
     30     DIV.subsubsection {
     31                    border-top: 1px dotted #99c;
     32                    /* border-left: 1px solid #99c; */
     33                    padding-left: 1em;
     34                    margin-bottom: 1.2em;
     35     }
     36     DIV.subsubsubsection {
     37                    border-top: 1px solid #ddf;
     38                    padding-left: 1em;
     39                    margin-bottom: 1.2em;
     40     }
     41
    2942         DIV.section {
    3043                 margin-bottom: 1.5em;
     
    4558                 margin: 0 0 1em 0;
    4659        }
    47         LI {
     60        UL LI {
    4861                list-style: none;
    4962        }
     
    5568                color: #113;
    5669                margin-bottom: 0.5em;
     70        }
     71        H4, H5, H6 {
     72                color: #113;
     73                margin-bottom: 1.0em;
     74        }
     75        H5 {
     76                font-weight: normal;
     77                font-style: italic;
     78                font-size: 100%;
     79                margin-top: 1.2em;
     80        }
     81        H6 {
     82                font-weight: bold;
     83                font-size: 85%;
     84                margin-top: 1.2em;
    5785        }
    5886     DIV#eggheader {
     
    101129       padding: 0.2em;
    102130       border: 1px solid #aac;
     131       border-collapse: collapse;
    103132       width: 100%;
    104133     }
     
    109138     }
    110139     TH {
    111        border-bottom: 1px solid black;
    112      } --></style></head>
     140       text-align: left;
     141       border-bottom: 1px solid #aac;
     142       padding: 0.25em 0.5em 0.25em 0.5em;
     143     }
     144     TD { padding: 0.25em 0.5em 0.25em 0.5em; }
     145     --></style></head>
    113146<body>
    114147<div id="header">
     
    127160<li>1.1 Generating MIME messages</li>
    128161<li>1.2 fixed .setup script to handle change in argument processing of csc</li>
    129 </ul></div>
     162<li>1.3 Added mime-get-attributes (suggested by Moe Aboulkheir)</li></ul></div>
    130163<div class="section">
    131164<h3>Requires</h3>
     
    143176<p>This egg provides utility procedures to handle Multipurpose Internet Mail Extensions (MIME) messages, defined in RFC2045 through RFC2049. This egg is supposed to be used with the <tt>rfc822</tt> egg.</p>
    144177<div class="subsection">
    145 <p><b>Quoted-printable encoding/decoding</b></p>
     178<h4>Quoted-printable encoding/decoding</h4>
    146179<p>A few functions to encode/decode Quoted-printable format, defined in RFC2045, section 6.7.</p>
    147180<dl>
     
    155188<dd>Decodes a Quoted-printable encoded string <tt>STRING</tt> and returns the result as a string.</dd></dl></div>
    156189<div class="subsection">
    157 <p><b>Utilities for header fields</b></p>
     190<h4>Utilities for header fields</h4>
    158191<p>A few utility procedures to parse MIME-specific header fields.</p>
    159192<dl>
     
    161194<dd>If <tt>FIELD</tt> is a valid header field for MIME-Version, returns its major and minor versions in a list. Otherwise, returns <tt>#f</tt>. It is allowed to pass <tt>#f</tt> to <tt>FIELD</tt>, so that you can directly pass the result of <tt>rfc822-header-ref</tt> to it. Given a parsed header list from <tt>rfc822-header-&gt;list</tt>, you can get the MIME version (currently, it should be <tt>(1 0)</tt>) by the following code:
    162195<pre>(mime-parse-version (rfc822-header-ref headers &quot;mime-version&quot;))</pre>Note: simple regexp such as <tt>&quot;\d+\.\d+&quot;</tt> doesn't do this job, for <tt>FIELD</tt> may contain comments between tokens.</dd>
     196<dt class="definition"><strong>procedure:</strong> (mime-get-attributes INPUT)</dt>
     197<dd>Reads an attribute/value list in the form <tt>;attr1=value1;attr2=value2</tt> from <tt>INPUT</tt> (which should be an open input-port) and returns it as an alist.</dd>
    163198<dt class="definition"><strong>procedure:</strong> (mime-parse-content-type FIELD)</dt>
    164199<dd>Parses the &quot;content-type&quot; header field, and returns a list such as:
     
    171206=&gt; &quot;this is some text&quot;</pre></dd></dl></div>
    172207<div class="subsection">
    173 <p><b>Streaming parser</b></p>
     208<h4>Streaming parser</h4>
    174209<p>The streaming parser is designed so that you can decide how to do with the message body before the entire message is read.</p>
    175210<dl>
     
    243278<dd>Reads in the body of mime message, decoding transfer encoding, and returns it as a string or writes it to a file, respectively.</dd></dl></div>
    244279<div class="subsection">
    245 <p><b>Message generator</b></p>
     280<h4>Message generator</h4>
    246281<p>The message generator generates a RFC822/MIME message out of <tt>:mime-part</tt> objects.</p>
    247282<dl>
     
    310345<div class="section">
    311346<h3>License</h3>
    312 <pre id="license">
    313347<pre>Copyright (c) 2000-2004 Shiro Kawai, All rights reserved.
    314348
     
    338372LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    339373NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    340 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</pre></pre></div></div>
     374SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</pre></div></div>
    341375<div id="footer">
    342376<hr /><a href="index.html">&lt; Egg index</a>
  • mime/trunk/mime.scm

    r5246 r5248  
    4848 (usual-integrations)
    4949 (uses mime:quoted-printable)
    50  (export mime-parse-version mime-parse-content-type
    51         mime-decode-word
     50 (export mime-token-chars mime-parse-version mime-get-attributes
     51         mime-parse-content-type mime-decode-word
    5252         mime-parse-message mime-retrieve-body
    5353         mime-body->string mime-body->file
     
    7272;;
    7373
     74(define mime-token-chars
     75  (char-set-difference
     76   (ucs-range->char-set #x21 #x7f)
     77   (char-set #\( #\) #\< #\> #\@ #\, #\; #\: #\\ #\" #\/ #\[ #\] #\? #\=)))
     78
    7479;; returns list of major and minor versions in integers
    7580(define mime-parse-version
    76   (let ((re-version (regexp "^([0-9]+)\.([0-9]+)$")))
     81  (let ((re-version (regexp "^([0-9]+)\\.([0-9]+)$")))
    7782    (lambda (field)
    7883      (and field
     
    8388                   (else #f)))))))
    8489
    85 ;; returns (<type> <subtype> (<attribute> . <value>) ...)
    86 (define (mime-parse-content-type field)
    87   (define token-chars
    88     (char-set-difference
    89      (ucs-range->char-set #x21 #x7f)
    90      (char-set #\( #\) #\< #\> #\@ #\, #\; #\: #\\ #\" #\/ #\[ #\] #\? #\=)))
     90;; reads attributes in the form ;attr1=val1;attr2=val2;... from input
     91;; and returns them as alist
     92(define (mime-get-attributes input)
    9193  (define cs-quote (char-set #\"))
    9294  (define (get-attributes input r)
    9395    (cond ((and-let* (((eqv? #\; (rfc822-next-token input '())))
    94                       (attr (rfc822-next-token input `(,token-chars)))
     96                      (attr (rfc822-next-token input `(,mime-token-chars)))
    9597                      ((string? attr))
    9698                      ((eqv? #\= (rfc822-next-token input '())))
    9799                      (val  (rfc822-next-token
    98100                             input
    99                              `(,token-chars
     101                             `(,mime-token-chars
    100102                               (,cs-quote . ,rfc822-quoted-string))))
    101103                      ((string? val)))
     
    103105           => (lambda (p) (get-attributes input (cons p r))))
    104106          (else (reverse! r))))
    105 
     107  (get-attributes input '()))
     108
     109;; returns (<type> <subtype> (<attribute> . <value>) ...)
     110(define (mime-parse-content-type field)
    106111  (and field
    107112       (call-with-input-string field
    108113         (lambda (input)
    109            (let* ((type    (rfc822-next-token input `(,token-chars)))
     114           (let* ((type    (rfc822-next-token input `(,mime-token-chars)))
    110115                  (slash   (rfc822-next-token input '()))
    111                   (subtype (rfc822-next-token input `(,token-chars))))
     116                  (subtype (rfc822-next-token input `(,mime-token-chars))))
    112117             (and (string? type)
    113118                  (eqv? #\/ slash)
     
    115120                  (cons* (string-downcase type)
    116121                         (string-downcase subtype)
    117                          (get-attributes input '()))))
    118            ))))
     122                         (mime-get-attributes input))))))))
    119123
    120124;; decode rfc2047-encoded word, i.e. "=?...?="
  • mime/trunk/mime.setup

    r5246 r5248  
    44 'mime
    55 '("mime.so" "mime.html")
    6  '((version 1.2)
     6 '((version 1.3)
    77   (documentation "mime.html")))
Note: See TracChangeset for help on using the changeset viewer.