p:send-mail-003

Test p:send-mail sending multipart mail.

Test nw-send-mail-003.xml is expected to pass.

It requires the following features: send-mail.

The pipeline


<p:declare-step xmlns:p="http://www.w3.org/ns/xproc" version="3.0">
   <p:output port="result"/>
   <!-- Clear the Sendria log -->
   <p:http-request href="http://localhost:1080/api/messages/" method="delete">
      <p:with-input>
         <p:empty/>
      </p:with-input>
   </p:http-request>
   <!-- Make sure that succeeded -->
   <p:if test=".?code != 'OK'">
      <p:error code="Q{{http://example.com/}}irrelevant">
         <p:with-input>
            <p:empty/>
         </p:with-input>
      </p:error>
   </p:if>
   <p:send-mail parameters="map{'host':'localhost', 'port':1025}" auth="map{'username':'username','password':'password'}">
      <p:with-input>
         <p:inline>
            <emx:Message xmlns:emx="URN:ietf:params:email-xml:" xmlns:rfc822="URN:ietf:params:rfc822:">
               <rfc822:from>
                  <emx:Address>
                     <emx:adrs>mailto:user@example.com</emx:adrs>
                     <emx:name>Example User</emx:name>
                  </emx:Address>
               </rfc822:from>
               <rfc822:to>
                  <emx:Address>
                     <emx:adrs>mailto:anotheruser@example.com</emx:adrs>
                     <emx:name>Another User</emx:name>
                  </emx:Address>
               </rfc822:to>
               <rfc822:subject>Multi-part Email</rfc822:subject>
               <emx:content type="text/plain">
          This is my text message.
        </emx:content>
            </emx:Message>
         </p:inline>
         <p:inline>
            <html xmlns="http://www.w3.org/1999/xhtml">
               <head>
                  <title>Hello, World</title>
               </head>
               <body>
                  <h1>Hello, World!</h1>
                  <p>This is my attachment.</p>
               </body>
            </html>
         </p:inline>
      </p:with-input>
   </p:send-mail>
   <!-- Check the Sendria log -->
   <p:http-request href="http://localhost:1080/api/messages/" method="get"/>
   <p:http-request href="http://localhost:1080/api/messages/" method="get"/>
   <p:http-request href="http://localhost:1080/api/messages/" method="get"/>
   <p:cast-content-type content-type="application/xml"/>
</p:declare-step>
MorganaXProc passing XML Calabash passing

Schematron validation


<s:schema xmlns:s="http://purl.oclc.org/dsdl/schematron" queryBinding="xslt2">
   <s:ns prefix="fn" uri="http://www.w3.org/2005/xpath-functions"/>
   <s:pattern name="Root must be map">
      <s:rule context="/fn:map">
         <s:assert test="fn:string[@key='code'] = 'OK'">Code must be 'OK'</s:assert>
         <s:assert test="fn:array[@key='data']/fn:map/fn:string[@key='subject']                             = 'Multi-part Email'">The subject must be correct</s:assert>
         <s:assert test="fn:array[@key='data']/fn:map/fn:string[@key='type']                             = 'multipart/mixed'">The content type must be multipart/mixed</s:assert>
      </s:rule>
   </s:pattern>
</s:schema>

Revision history

12 Oct 2024, Norm Tovey-Walsh

Avoid content-type error if clearing the log fails.

30 May 2024, Norm Tovey-Walsh

Test for the p:send-mail step.