aboutsummaryrefslogtreecommitdiffstats
path: root/doc/user-guide/docbook.xsl
blob: 21d6b08ed03718e6327f0491e731a9f8350e436b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<?xml version='1.0'?>
<!--
	Convert BitlBee XML documentation to DocBook
	(C) 2004 Jelmer Vernooij
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:exsl="http://exslt.org/common"
	version="1.1"
	extension-element-prefixes="exsl">

	<xsl:output method="xml" encoding="UTF-8" doctype-public="-//OASIS//DTD DocBook XML V4.2//EN" indent="yes" doctype-system="http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"/>

	<xsl:strip-space elements="*"/>

	<xsl:template match="ircline">
		<xsl:element name="prompt"><xsl:text>&lt; </xsl:text><xsl:value-of select="@nick"/><xsl:text>&gt; </xsl:text></xsl:element>
		<xsl:element name="userinput"><xsl:value-of select="normalize-space(.)"/></xsl:element><xsl:text>&#10;</xsl:text>
	</xsl:template>

	<xsl:template match="ircaction">
		<xsl:text> * </xsl:text><xsl:value-of select="@nick"/><xsl:text> </xsl:text><xsl:value-of select="normalize-space(.)"/><xsl:text>&#10;</xsl:text>
	</xsl:template>

	<xsl:template match="ircexample">
		<xsl:element name="screen">
			<xsl:for-each select="ircline|ircaction">
				<xsl:apply-templates select="."/>
			</xsl:for-each>
		</xsl:element>
	</xsl:template>


	<!-- This is needed to copy content unchanged -->
	<xsl:template match="@*|node()">
		<xsl:copy>
			<xsl:apply-templates select="@*|node()"/>
		</xsl:copy>
	</xsl:template>

	<xsl:template name="subcmd-list">
		<xsl:if test="bitlbee-command != ''">
			<xsl:element name="variablelist">
				<xsl:for-each select="bitlbee-command">
					<xsl:element name="varlistentry">
						<xsl:element name="term">
							<xsl:value-of select="@name"/>
						</xsl:element>
						<xsl:element name="listitem">
							<xsl:element name="para">
								<xsl:value-of select="short-description"/>
							</xsl:element>
						</xsl:element>
					</xsl:element>
				</xsl:for-each>
			</xsl:element>
		</xsl:if>
	</xsl:template>

	<xsl:template match="command-list">
		<xsl:call-template name="subcmd-list"/>
	</xsl:template>

	<xsl:template match="bitlbee-setting">
		<xsl:element name="sect1">
			<xsl:attribute name="id">
				<xsl:text>set_</xsl:text>
				<xsl:value-of select="@name"/>
			</xsl:attribute>
			<xsl:element name="title"><xsl:value-of select="@name"/></xsl:element>

			<xsl:element name="simplelist">
				<xsl:element name="member">
					<xsl:text>Type: </xsl:text><xsl:value-of select="@type"/>
				</xsl:element>
			</xsl:element>

			<xsl:for-each select="description/para">
				<xsl:apply-templates select="."/>
			</xsl:for-each>

		</xsl:element>
	</xsl:template>

	<xsl:template name="cmd">
		<xsl:param name="prefix"/>
		<xsl:variable name="thiscmd"><xsl:value-of select="$prefix"/><xsl:value-of select="@name"/></xsl:variable>
		<xsl:attribute name="id">
			<xsl:text>cmd_</xsl:text>
			<xsl:value-of select="translate($thiscmd,' ','_')"/>
		</xsl:attribute>
		<xsl:element name="title"><xsl:value-of select="$thiscmd"/>
			<xsl:if test="short-description">
				<xsl:text> - </xsl:text>
				<xsl:value-of select="short-description"/>
			</xsl:if>
		</xsl:element>

		<xsl:element name="formalpara">
			<xsl:element name="title"><xsl:text>Syntax:</xsl:text></xsl:element>
			<xsl:element name="para">
				<xsl:element name="programlisting">
					<xsl:for-each select="syntax">
						<xsl:value-of select="normalize-space(.)"/><xsl:text>&#10;</xsl:text>
					</xsl:for-each>
				</xsl:element>
			</xsl:element>
		</xsl:element>

		<xsl:for-each select="description/para">
			<xsl:apply-templates select="."/>
		</xsl:for-each>

		<xsl:for-each select="ircexample">
			<xsl:apply-templates select="."/>
		</xsl:for-each>

		<!--<xsl:call-template name="subcmd-list"/>-->

		<xsl:for-each select="bitlbee-command">
			<xsl:element name="sect2">
				<xsl:call-template name="cmd">
					<xsl:with-param name="prefix"><xsl:value-of select="$thiscmd"/><xsl:text> </xsl:text>
					</xsl:with-param>
				</xsl:call-template>
			</xsl:element>
		</xsl:for-each>
	</xsl:template>

	<xsl:template match="bitlbee-command">
		<xsl:element name="sect1">
			<xsl:call-template name="cmd">
				<xsl:with-param name="prefix" select="''"/>
			</xsl:call-template>
		</xsl:element>
	</xsl:template>

	</xsl:stylesheet>
="nf">headers mime.headers end # copy data from msg properties storage to standard mime. headers # i've now seen it where the existing headers had heaps on stuff, and the msg#props had # practically nothing. think it was because it was a tnef - msg conversion done by exchange. def populate_headers # construct a From value # should this kind of thing only be done when headers don't exist already? maybe not. if its # sent, then modified and saved, the headers could be wrong? # hmmm. i just had an example where a mail is sent, from an internal user, but it has transport # headers, i think because one recipient was external. the only place the senders email address # exists is in the transport headers. so its maybe not good to overwrite from. # recipients however usually have smtp address available. # maybe we'll do it for all addresses that are smtp? (is that equivalent to # sender_email_address !~ /^\// name, email = props.sender_name, props.sender_email_address if props.sender_addrtype == 'SMTP' headers['From'] = if name and email and name != email [%{"#{name}" <#{email}>}] else [email || name] end elsif !headers.has_key?('From') # some messages were never sent, so that sender stuff isn't filled out. need to find another # way to get something # what about marking whether we thing the email was sent or not? or draft? # for partition into an eventual Inbox, Sent, Draft mbox set? # i've now seen cases where this stuff is missing, but exists in transport message headers, # so maybe i should inhibit this in that case. if email # disabling this warning for now #Log.warn "* no smtp sender email address available (only X.400). creating fake one" # this is crap. though i've specially picked the logic so that it generates the correct # email addresses in my case (for my organisation). # this user stuff will give valid email i think, based on alias. user = name ? name.sub(/(.*), (.*)/, "\\2.\\1") : email[/\w+$/].downcase domain = (email[%r{^/O=([^/]+)}i, 1].downcase + '.com' rescue email) headers['From'] = [name ? %{"#{name}" <#{user}@#{domain}>} : "<#{user}@#{domain}>" ] elsif name # we only have a name? thats screwed up. # disabling this warning for now #Log.warn "* no smtp sender email address available (only name). creating fake one" headers['From'] = [%{"#{name}"}] else # disabling this warning for now #Log.warn "* no sender email address available at all. FIXME" end # else we leave the transport message header version end # for all of this stuff, i'm assigning in utf8 strings. # thats ok i suppose, maybe i can say its the job of the mime class to handle that. # but a lot of the headers are overloaded in different ways. plain string, many strings # other stuff. what happens to a person who has a " in their name etc etc. encoded words # i suppose. but that then happens before assignment. and can't be automatically undone # until the header is decomposed into recipients. recips_by_type = recipients.group_by { |r| r.type } # i want to the the types in a specific order. [:to, :cc, :bcc].each do |type| # don't know why i bother, but if we can, we try to sort recipients by the numerical part # of the ole name, or just leave it if we can't recips = recips_by_type[type] recips = (recips.sort_by { |r| r.obj.name[/\d{8}$/].hex } rescue recips) # switched to using , for separation, not ;. see issue #4 # recips.empty? is strange. i wouldn't have thought it possible, but it was right? headers[type.to_s.sub(/^(.)/) { $1.upcase }] = [recips.join(', ')] if recips and !recips.empty? end headers['Subject'] = [props.subject] if props.subject # fill in a date value. by default, we won't mess with existing value hear if !headers.has_key?('Date') # we want to get a received date, as i understand it. # use this preference order, or pull the most recent? keys = %w[message_delivery_time client_submit_time last_modification_time creation_time] time = keys.each { |key| break time if time = props.send(key) } time = nil unless Date === time # now convert and store # this is a little funky. not sure about time zone stuff either? # actually seems ok. maybe its always UTC and interpreted anyway. or can be timezoneless. # i have no timezone info anyway. # in gmail, i see stuff like 15 Jan 2007 00:48:19 -0000, and it displays as 11:48. # can also add .localtime here if desired. but that feels wrong. headers['Date'] = [Time.iso8601(time.to_s).rfc2822] if time end # some very simplistic mapping between internet message headers and the # mapi properties # any of these could be causing duplicates due to case issues. the hack in #to_mime # just stops re-duplication at that point. need to move some smarts into the mime # code to handle it. mapi_header_map = [ [:internet_message_id, 'Message-ID'], [:in_reply_to_id, 'In-Reply-To'], # don't set these values if they're equal to the defaults anyway [:importance, 'Importance', proc { |val| val.to_s == '1' ? nil : val }], [:priority, 'Priority', proc { |val| val.to_s == '1' ? nil : val }], [:sensitivity, 'Sensitivity', proc { |val| val.to_s == '0' ? nil : val }], # yeah? [:conversation_topic, 'Thread-Topic'], # not sure of the distinction here # :originator_delivery_report_requested ?? [:read_receipt_requested, 'Disposition-Notification-To', proc { |val| from }] ] mapi_header_map.each do |mapi, mime, *f| next unless q = val = props.send(mapi) or headers.has_key?(mime) next if f[0] and !(val = f[0].call(val)) headers[mime] = [val.to_s] end end # redundant? def type props.message_class[/IPM\.(.*)/, 1].downcase rescue nil end # shortcuts to some things from the headers %w[From To Cc Bcc Subject].each do |key| define_method(key.downcase) { headers[key].join(' ') if headers.has_key?(key) } end def body_to_mime # to create the body # should have some options about serializing rtf. and possibly options to check the rtf # for rtf2html conversion, stripping those html tags or other similar stuff. maybe want to # ignore it in the cases where it is generated from incoming html. but keep it if it was the # source for html and plaintext. if props.body_rtf or props.body_html # should plain come first? mime = SimpleMime.new "Content-Type: multipart/alternative\r\n\r\n" # its actually possible for plain body to be empty, but the others not. # if i can get an html version, then maybe a callout to lynx can be made... mime.parts << SimpleMime.new("Content-Type: text/plain\r\n\r\n" + props.body) if props.body # this may be automatically unwrapped from the rtf if the rtf includes the html mime.parts << SimpleMime.new("Content-Type: text/html\r\n\r\n" + props.body_html) if props.body_html # temporarily disabled the rtf. its just showing up as an attachment anyway. #mime.parts << SimpleMime.new("Content-Type: text/rtf\r\n\r\n" + props.body_rtf) if props.body_rtf # its thus currently possible to get no body at all if the only body is rtf. that is not # really acceptable FIXME mime else # check no header case. content type? etc?. not sure if my SimpleMime class will accept Log.debug "taking that other path" # body can be nil, hence the to_s SimpleMime.new "Content-Type: text/plain\r\n\r\n" + props.body.to_s end end def to_mime # intended to be used for IPM.note, which is the email type. can use it for others if desired, # YMMV Log.warn "to_mime used on a #{props.message_class}" unless props.message_class == 'IPM.Note' # we always have a body mime = body = body_to_mime # If we have attachments, we take the current mime root (body), and make it the first child # of a new tree that will contain body and attachments. unless attachments.empty? mime = SimpleMime.new "Content-Type: multipart/mixed\r\n\r\n" mime.parts << body # i don't know any better way to do this. need multipart/related for inline images # referenced by cid: urls to work, but don't want to use it otherwise... related = false attachments.each do |attach| part = attach.to_mime related = true if part.headers.has_key?('Content-ID') or part.headers.has_key?('Content-Location') mime.parts << part end mime.headers['Content-Type'] = ['multipart/related'] if related end # at this point, mime is either # - a single text/plain, consisting of the body ('taking that other path' above. rare) # - a multipart/alternative, consiting of a few bodies (plain and html body. common) # - a multipart/mixed, consisting of 1 of the above 2 types of bodies, and attachments. # we add this standard preamble if its multipart # FIXME preamble.replace, and body.replace both suck. # preamble= is doable. body= wasn't being done because body will get rewritten from parts # if multipart, and is only there readonly. can do that, or do a reparse... # The way i do this means that only the first preamble will say it, not preambles of nested # multipart chunks. mime.preamble.replace "This is a multi-part message in MIME format.\r\n" if mime.multipart? # now that we have a root, we can mix in all our headers headers.each do |key, vals| # don't overwrite the content-type, encoding style stuff next if mime.headers.has_key? key # some new temporary hacks next if key =~ /content-type/i and vals[0] =~ /base64/ next if mime.headers.keys.map(&:downcase).include? key.downcase mime.headers[key] += vals end # just a stupid hack to make the content-type header last, when using OrderedHash mime.headers['Content-Type'] = mime.headers.delete 'Content-Type' mime end end class Attachment def to_mime # TODO: smarter mime typing. mimetype = props.attach_mime_tag || 'application/octet-stream' mime = SimpleMime.new "Content-Type: #{mimetype}\r\n\r\n" mime.headers['Content-Disposition'] = [%{attachment; filename="#{filename}"}] mime.headers['Content-Transfer-Encoding'] = ['base64'] mime.headers['Content-Location'] = [props.attach_content_location] if props.attach_content_location mime.headers['Content-ID'] = [props.attach_content_id] if props.attach_content_id # data.to_s for now. data was nil for some reason. # perhaps it was a data object not correctly handled? # hmmm, have to use read here. that assumes that the data isa stream. # but if the attachment data is a string, then it won't work. possible? data_str = if @embedded_msg mime.headers['Content-Type'] = 'message/rfc822' # lets try making it not base64 for now mime.headers.delete 'Content-Transfer-Encoding' # not filename. rather name, or something else right? # maybe it should be inline?? i forget attach_method / access meaning mime.headers['Content-Disposition'] = [%{attachment; filename="#{@embedded_msg.subject}"}] @embedded_msg.to_mime.to_s elsif @embedded_ole # kind of hacky io = StringIO.new Ole::Storage.new io do |ole| ole.root.type = :dir Ole::Storage::Dirent.copy @embedded_ole, ole.root end io.string else # FIXME: shouldn't be required data.read.to_s rescue '' end mime.body.replace @embedded_msg ? data_str : Base64.encode64(data_str).gsub(/\n/, "\r\n") mime end end class Msg < Message def populate_headers super if !headers.has_key?('Date') # can employ other methods for getting a time. heres one in a similar vein to msgconvert.pl, # ie taking the time from an ole object time = @root.ole.dirents.map { |dirent| dirent.modify_time || dirent.create_time }.compact.sort.last headers['Date'] = [Time.iso8601(time.to_s).rfc2822] if time end end end end