﻿<?xml version="1.0" encoding="utf-8"?>
<xs:schema version="1.0" xmlns:em="http://daisley-harrison.com/namespaces/EmailTemplate" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://daisley-harrison.com/namespaces/EmailTemplate" xmlns:xs="http://www.w3.org/2001/XMLSchema">
	<!--
		Copyright (c) 2009, Aaron G. Daisley-Harrison - All rights reserved.
 
		Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

		Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

		Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer 
		in the documentation and/or other materials provided with the distribution.

		Neither the name of Daisley-Harison Software nor the names of its contributors may be used to endorse or promote products derived 
		from this software without specific prior written permission.

		THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
		INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 
		IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, 
		OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
		OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
		OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
		EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
		-->
	<xs:import namespace="http://www.w3.org/1999/xhtml" />
	<xs:element name="body">
		<xs:annotation>
			<xs:documentation>
				The body of the email
			</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:choice minOccurs="0">
				<xs:element xmlns:q1="http://www.w3.org/1999/xhtml" ref="q1:html"  maxOccurs="1"/>
				<xs:group ref="em:template-elements" maxOccurs="unbounded"/>
			</xs:choice>
			<xs:attribute name="mime-type" type="em:mime-type" use="optional" />
		</xs:complexType>
	</xs:element>
	<xs:simpleType name="mime-type">
		<xs:annotation>
			<xs:documentation>
				email mime-type
			</xs:documentation>
		</xs:annotation>
		<xs:restriction base="xs:string">
			<xs:pattern value="([a-z][A-Z])+([0-9][a-z][A-Z][/_/-])*//([a-z][A-Z])+([0-9][a-z][A-Z][/_/-])*"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="cond">
		<xs:restriction base="xs:string">
			<xs:enumeration value="equal"/>
			<xs:enumeration value="="/>
			<xs:enumeration value="eq"/>
			<xs:enumeration value="not-equal"/>
			<xs:enumeration value="not-eq"/>
			<xs:enumeration value="!="/>
			<xs:enumeration value="!eq"/>
			<xs:enumeration value="&lt;&gt;"/>
			<xs:enumeration value="ne"/>
			<xs:enumeration value="exists"/>
			<xs:enumeration value="!exists"/>
			<xs:enumeration value="not-exists"/>
			<xs:enumeration value="?"/>
			<xs:enumeration value="!?"/>
			<xs:enumeration value="gt"/>
			<xs:enumeration value="&gt;"/>
			<xs:enumeration value="lt"/>
			<xs:enumeration value="&lt;"/>
			<xs:enumeration value="ge"/>
			<xs:enumeration value="&gt;="/>
			<xs:enumeration value="le"/>
			<xs:enumeration value="&lt;="/>
			<xs:enumeration value="whitespace"/>
			<xs:enumeration value="!whitespace"/>
			<xs:enumeration value="not-whitespace"/>
			<xs:enumeration value="regex"/>
			<xs:enumeration value="!regex"/>
			<xs:enumeration value="not-regex"/>
			<xs:enumeration value="odd"/>
			<xs:enumeration value="even"/>
			<xs:enumeration value="contains"/>
			<xs:enumeration value="!contains"/>
			<xs:enumeration value="not-contains"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:group name="template-elements">
		<xs:choice>
			<xs:element ref="em:if" maxOccurs="unbounded"/>
			<xs:element ref="em:choose" maxOccurs="unbounded"/>
			<xs:element ref="em:format" maxOccurs="unbounded"/>
			<xs:element ref="em:regex" maxOccurs="unbounded"/>
			<xs:element ref="em:linked-image" maxOccurs="unbounded"/>
			<xs:element ref="em:for-each" maxOccurs="unbounded"/>
		</xs:choice>
	</xs:group>
	<xs:attributeGroup name="conditional-expression">
		<xs:attribute name="select" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>
					a template expression to be evaluated
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="cond" type="em:cond" use="optional" default="=">
			<xs:annotation>
				<xs:documentation>
					The condition operation to be performed
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="test" type="xs:string" use="optional">
			<xs:annotation>
				<xs:documentation>
					The value to be test against the expression using the specified condition operator
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
	</xs:attributeGroup>
	<xs:element name="if">
		<xs:annotation>
			<xs:documentation>
				if statement
				when the if statement evaluates to true
				the content will be included in the output stream
			</xs:documentation>
		</xs:annotation>
		<xs:complexType mixed="true">
			<xs:group ref="em:template-elements"/>
			<xs:attributeGroup ref="conditional-expression"/>
		</xs:complexType>
	</xs:element>
	<xs:element name="for-each">
		<xs:annotation>
			<xs:documentation>
				for-each statement
				loop through an enumerated item collection
				the content will be included in the output stream, once for each item in the collection
			</xs:documentation>
		</xs:annotation>
		<xs:complexType mixed="true">
			<xs:group ref="em:template-elements"/>
			<xs:attribute name="select" type="xs:string" use="optional" />
			<xs:attribute name="as" type="xs:string" use="optional" />
		</xs:complexType>
	</xs:element>
	<xs:element name="format">
		<xs:annotation>
			<xs:documentation>
				format the results of an expression with a string pattern expression
				(uses String.Format)
			</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:attribute name="select" type="xs:string" use="required" >
				<xs:annotation>
					<xs:documentation>
						The template expression to be evaluated and formatted
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="pattern" type="xs:string" use="required" >
				<xs:annotation>
					<xs:documentation>
						The string format pattern to be applied
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
		</xs:complexType>
	</xs:element>
	<xs:element name="replace">
		<xs:annotation>
			<xs:documentation>
				Do a regular expression replace on the results of an expression with the specified pattern and replace expression
				(uses Regex)
			</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:attribute name="select" type="xs:string" use="required" >
				<xs:annotation>
					<xs:documentation>
						The template expression to be evaluated and replace performed on it's result
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="pattern" type="xs:string" use="required">
				<xs:annotation>
					<xs:documentation>
						The regular expression pattern
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="replace" type="xs:string" use="required" >
				<xs:annotation>
					<xs:documentation>
						The regular expression replace expression
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
		</xs:complexType>
	</xs:element>
	<xs:element name="linked-image">
		<xs:annotation>
			<xs:documentation>
				Creates an html image tag and automatically embedded the specified resource 
			</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:attribute name="source" type="xs:string" use="required">
				<xs:annotation>
					<xs:documentation>
						An expression that evaluates to a resource uri
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="alt" type="xs:string" use="required">
				<xs:annotation>
					<xs:documentation>
						The contents of the html img alt attribute
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="style" type="xs:string" use="optional">
				<xs:annotation>
					<xs:documentation>
						The contents of the html img style attribute
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>
			<xs:attribute name="class" type="xs:string" use="optional" >
				<xs:annotation>
					<xs:documentation>
						The contents of the html img class attribute
					</xs:documentation>
				</xs:annotation>
			</xs:attribute>

		</xs:complexType>
	</xs:element>
	<xs:element name="choose">
		<xs:complexType mixed="true">
			<xs:sequence>
				<xs:element name="when" maxOccurs="unbounded">
					<xs:complexType mixed="true">
						<xs:group ref="em:template-elements"/>
						<xs:attributeGroup ref="conditional-expression"/>
					</xs:complexType>
				</xs:element>
				<xs:element name="otherwise" maxOccurs="1">
					<xs:annotation>
						<xs:documentation>
							The choose statement resolves to the content of the otherwise element if none of the when element expressions are true
						</xs:documentation>
					</xs:annotation>
					<xs:complexType mixed="true">
						<xs:group ref="em:template-elements"/>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:attributeGroup name="linked-resource-attributes">
		<xs:attribute name="id" type="xs:ID" use="required">
			<xs:annotation>
				<xs:documentation>
					The id of the embedded resource. Used to reference the resource from inside an email body
					eg: &lt;img src="cid:myID"/&gt;
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="url" type="xs:anyURI" use="required">
			<xs:annotation>
				<xs:documentation>
					The url of the resourc
				</xs:documentation>
			</xs:annotation>
		</xs:attribute>
		<xs:attribute name="mime-type" type="em:mime-type" use="optional" />
		<xs:attribute name="encoding" type="xs:string" use="optional" />
		<xs:attribute name="transfer-encoding" type="xs:string" use="optional" />
	</xs:attributeGroup>
	<xs:element name="linked-resources">
		<xs:complexType>
			<xs:sequence>
				<xs:element name="linked-resource" maxOccurs="unbounded">
					<xs:annotation>
						<xs:documentation>
							An embedded linked resource referenced in the email
						</xs:documentation>
					</xs:annotation>
					<xs:complexType>
						<xs:attributeGroup ref="em:linked-resource-attributes"/>
					</xs:complexType>
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>
	<xs:element name="email-template">
		<xs:complexType>
			<xs:all>
				<xs:element name="description" type="xs:string" />
				<xs:element name="headers">
					<xs:complexType>
						<xs:sequence>
							<xs:element maxOccurs="unbounded" name="header">
								<xs:annotation>
									<xs:documentation>
										A custom email header to be included with the message
									</xs:documentation>
								</xs:annotation>
								<xs:complexType>
									<xs:attribute name="name" type="xs:string" use="required">
										<xs:annotation>
											<xs:documentation>
												The email header name
											</xs:documentation>
										</xs:annotation>
									</xs:attribute>
									<xs:attribute name="value" type="xs:string" use="required">
										<xs:annotation>
											<xs:documentation>
												The email header value
											</xs:documentation>
										</xs:annotation>
									</xs:attribute>

								</xs:complexType>
							</xs:element>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
				<xs:element ref="em:linked-resources"/>
				<xs:element name="attachments">
					<xs:complexType>
						<xs:sequence>
							<xs:element maxOccurs="unbounded" name="attachment">
								<xs:annotation>
									<xs:documentation>
										A attachment to be embedded inslide the email message
									</xs:documentation>
								</xs:annotation>
								<xs:complexType>
									<xs:attributeGroup ref="em:linked-resource-attributes"/>
									<xs:attribute name="name" type="xs:string" use="required">
										<xs:annotation>
											<xs:documentation>
												The name of the attachment to be shown in the email client
											</xs:documentation>
										</xs:annotation>
									</xs:attribute>
								</xs:complexType>
							</xs:element>
						</xs:sequence>
					</xs:complexType>
				</xs:element>
				<xs:element name="from" type="xs:string" maxOccurs="1">
					<xs:annotation>
						<xs:documentation>
							The email address of the orginator of the email message
						</xs:documentation>
					</xs:annotation>
				</xs:element>
				<xs:element name="sender" type="xs:string" maxOccurs="1">
					<xs:annotation>
						<xs:documentation>
							The email address of the sender of the email message
						</xs:documentation>
					</xs:annotation>
				</xs:element>
				<xs:element name="reply-to" type="xs:string" maxOccurs="1">
					<xs:annotation>
						<xs:documentation>
							The email address to reply for this email message
						</xs:documentation>
					</xs:annotation>
				</xs:element>
				<xs:element name="to" type="xs:string" maxOccurs="1">
					<xs:annotation>
						<xs:documentation>
							Comma delimited list of email addresses to send the message to
						</xs:documentation>
					</xs:annotation>
				</xs:element>
				<xs:element name="cc" type="xs:string" maxOccurs="1">
					<xs:annotation>
						<xs:documentation>
							Comma delimited list of email addresses to send a carbon copy of the message to
						</xs:documentation>
					</xs:annotation>
				</xs:element>
				<xs:element name="bcc" type="xs:string" maxOccurs="1">
					<xs:annotation>
						<xs:documentation>
							Comma delimited list of email addresses to send a blind carbon copy of the message to
						</xs:documentation>
					</xs:annotation>
				</xs:element>
				<xs:element name="subject" type="xs:string" maxOccurs="1">
					<xs:annotation>
						<xs:documentation>
							The email subject line
						</xs:documentation>
					</xs:annotation>
				</xs:element>
				<xs:element ref="em:body"/>
				<xs:element name="alternate-views">
					<xs:element name="alternate-view" maxOccurs="unbounded">
					<xs:annotation>
						<xs:documentation>
							An alternate view of the email message
						</xs:documentation>
					</xs:annotation>
					<xs:complexType>
						<xs:sequence>
							<xs:element ref="em:linked-resources"/>
							<xs:element ref="em:body"/>
						</xs:sequence>
						<xs:attribute name="id" type="xs:string" use="required" />
						<xs:attribute name="mime-type" type="xs:string" use="required" />
						<xs:attribute name="base-uri" type="xs:string" use="required" />
						<xs:attribute name="encoding" type="xs:string" use="required" />
					</xs:complexType>
				</xs:element>
				</xs:element>
			</xs:all>
			<xs:attribute name="delivery-notification" default="never">
				<xs:annotation>
					<xs:documentation>
						The delivery notification options for e-mail.
					</xs:documentation>
				</xs:annotation>
				
				<xs:simpleType>
					<xs:list>
						<xs:simpleType>
							<xs:restriction base="xs:string">
								<xs:enumeration value="never">
									<xs:annotation>
										<xs:documentation>
											No notification will be sent
										</xs:documentation>
									</xs:annotation>
								</xs:enumeration>
								<xs:enumeration value="delayed">
									<xs:annotation>
										<xs:documentation>
											Sender will be notified when message delivery is delayed
										</xs:documentation>
									</xs:annotation>
								</xs:enumeration>
								<xs:enumeration value="done">
										<xs:annotation>
											<xs:documentation>
												Sender will be notified when message delivery is done
											</xs:documentation>
										</xs:annotation>
									</xs:enumeration>
								<xs:enumeration value="onfailure">
									<xs:annotation>
										<xs:documentation>
											Sender will be notified if message delivery failed
										</xs:documentation>
									</xs:annotation>
								</xs:enumeration>
								<xs:enumeration value="onsuccess">
									<xs:annotation>
										<xs:documentation>
											Sender will be notified if message delivery was successful
										</xs:documentation>
									</xs:annotation>
								</xs:enumeration>
							</xs:restriction>
						</xs:simpleType>
					</xs:list>
				</xs:simpleType>
			</xs:attribute>
			<xs:attribute name="priority" default="normal">
				<xs:annotation>
					<xs:documentation>
						The priority of the email message
					</xs:documentation>
				</xs:annotation>
				<xs:simpleType>
					<xs:restriction base="xs:string">
						<xs:enumeration value="normal">
							<xs:annotation>
								<xs:documentation>
									Mail will be sent marked normal priority
								</xs:documentation>
							</xs:annotation>
						</xs:enumeration>
						<xs:enumeration value="low">
							<xs:annotation>
								<xs:documentation>
									Mail will be sent marked low priority
								</xs:documentation>
							</xs:annotation>
						</xs:enumeration>
						<xs:enumeration value="high">
							<xs:annotation>
								<xs:documentation>
									Mail will be sent marked high priority
								</xs:documentation>
							</xs:annotation>
						</xs:enumeration>
					</xs:restriction>
				</xs:simpleType>
			</xs:attribute>
		</xs:complexType>
	</xs:element>
</xs:schema>
