Skip to content
Snippets Groups Projects
Select Git revision
  • 94d66be375b108c61bd05fc08b59e87c6d8fc81c
  • master default protected
  • 9.0
  • 8.0
  • nt-tools
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2020
  • v8.0.2018
  • v8.0.2016
  • v8.0.2014
  • v8.0.2012
  • v8.0.2008
  • v8.0.2006
  • v8.0.2004
  • v8.0.2002
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
41 results

builtin.cmod

Blame
  • PEM.pmod 4.83 KiB
    /* PEM.pmod
     *
     * Support for parsing PEM-style messages.
     */
    
    class encapsulated_message {
    
      import ._PEM;
    
      string boundary;
      string body;
      mapping(string:string) headers;
    
      object init(string eb, string contents)
      {
        boundary = eb;
    
        // werror(sprintf("init: contents = '%s\n'", contents));
    
        if (rfc822_start_re->match(contents))
          {
    	array a = MIME.parse_headers(contents);
    	headers = a[0];
    	body = a[1];
          } else {
    	headers = 0;
    	body = contents;
          }
        return this_object();
      }
      
      string decoded_body()
      {
        return MIME.decode_base64(body);
      }
    
      string get_boundary()
      {
        return extract_boundary(boundary);
      }
    
      string canonical_body()
      {
        /* Replace singular LF with CRLF */
        array lines = body / "\n";
    
        /* Make all lines terminated with \r (but the last, which is
         * either empty or a "line" that was not terminated). */
        for(int i=0; i < sizeof(lines)-1; i++)
          if (!strlen(lines[i]) || (lines[i][-1] != '\r'))
    	lines[i] += "\r";
        return lines * "\n";
      }
    
      string to_string()
      {
        string s = (headers
    		? Array.map(indices(headers),
    			    lambda(string hname, mapping(string:string) h)
    			    {
    			      return hname+": "+h[hname];
    			    }, headers) * "\n"
    			    : "");
        return s + "\n\n" + body;
      }
    }
    
    class rfc934 {
    
      import ._PEM;