An email to be sent using sendmail

Introduced properties

fun bcc: Array[String]

sendmail :: Mail :: bcc

Recipients of a blind carbon copy of the message
protected fun bcc=(bcc: Array[String])

sendmail :: Mail :: bcc=

Recipients of a blind carbon copy of the message
fun cc: Array[String]

sendmail :: Mail :: cc

Recipients of a carbon copy of the message
protected fun cc=(cc: Array[String])

sendmail :: Mail :: cc=

Recipients of a carbon copy of the message
fun content: String

sendmail :: Mail :: content

Content of this mail
fun content=(content: String)

sendmail :: Mail :: content=

Content of this mail
init defaultinit(from: String, subject: String, content: String)

sendmail :: Mail :: defaultinit

fun encrypt_with_base64: Bool

sendmail :: Mail :: encrypt_with_base64

Should the content of this email be encrypted using base64?
protected fun encrypt_with_base64=(encrypt_with_base64: Bool)

sendmail :: Mail :: encrypt_with_base64=

Should the content of this email be encrypted using base64?
fun from: String

sendmail :: Mail :: from

Sender of this email
fun from=(from: String)

sendmail :: Mail :: from=

Sender of this email
fun header: HashMap[String, String]

sendmail :: Mail :: header

Metadata in the header of this mail
protected fun header=(header: HashMap[String, String])

sendmail :: Mail :: header=

Metadata in the header of this mail
fun send: Bool

sendmail :: Mail :: send

Send this mail using the sendmail command
fun subject: String

sendmail :: Mail :: subject

Subject of this mail
fun subject=(subject: String)

sendmail :: Mail :: subject=

Subject of this mail
fun to: Array[String]

sendmail :: Mail :: to

Recipients of the message
protected fun to=(to: Array[String])

sendmail :: Mail :: to=

Recipients of the message

Redefined properties

redef type SELF: Mail

sendmail $ Mail :: SELF

Type of this instance, automatically specialized in every class
redef fun to_s: String

sendmail $ Mail :: to_s

User readable representation of self.

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun bcc: Array[String]

sendmail :: Mail :: bcc

Recipients of a blind carbon copy of the message
protected fun bcc=(bcc: Array[String])

sendmail :: Mail :: bcc=

Recipients of a blind carbon copy of the message
fun cc: Array[String]

sendmail :: Mail :: cc

Recipients of a carbon copy of the message
protected fun cc=(cc: Array[String])

sendmail :: Mail :: cc=

Recipients of a carbon copy of the message
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
fun content: String

sendmail :: Mail :: content

Content of this mail
fun content=(content: String)

sendmail :: Mail :: content=

Content of this mail
init defaultinit(from: String, subject: String, content: String)

sendmail :: Mail :: defaultinit

fun encrypt_with_base64: Bool

sendmail :: Mail :: encrypt_with_base64

Should the content of this email be encrypted using base64?
protected fun encrypt_with_base64=(encrypt_with_base64: Bool)

sendmail :: Mail :: encrypt_with_base64=

Should the content of this email be encrypted using base64?
fun from: String

sendmail :: Mail :: from

Sender of this email
fun from=(from: String)

sendmail :: Mail :: from=

Sender of this email
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
fun header: HashMap[String, String]

sendmail :: Mail :: header

Metadata in the header of this mail
protected fun header=(header: HashMap[String, String])

sendmail :: Mail :: header=

Metadata in the header of this mail
init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun send: Bool

sendmail :: Mail :: send

Send this mail using the sendmail command
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
fun subject: String

sendmail :: Mail :: subject

Subject of this mail
fun subject=(subject: String)

sendmail :: Mail :: subject=

Subject of this mail
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
fun to: Array[String]

sendmail :: Mail :: to

Recipients of the message
protected fun to=(to: Array[String])

sendmail :: Mail :: to=

Recipients of the message
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
package_diagram sendmail::Mail Mail core::Object Object sendmail::Mail->core::Object

Parents

interface Object

core :: Object

The root of the class hierarchy.

Class definitions

sendmail $ Mail
# An email to be sent using `sendmail`
class Mail

	# Sender of this email
	var from: String is writable

	# Recipients of the message
	var to = new Array[String]

	# Recipients of a carbon copy of the message
	var cc = new Array[String]

	# Recipients of a blind carbon copy of the message
	var bcc = new Array[String]

	# Subject of this mail
	var subject: String is writable

	# Content of this mail
	var content: String is writable

	# Metadata in the header of this mail
	var header = new HashMap[String, String]

	# Should the content of this email be encrypted using base64?
	#
	# This will also set the header `Content-Transfer-Encoding` to base64.
	# By default, the encoding is 8bit.
	var encrypt_with_base64 = false

	# Send this mail using the `sendmail` command
	#
	# require: `sendmail_is_available`
	fun send: Bool
	do
		assert sendmail_is_available

		# All recipients
		var all = new Array[String]
		all.add_all to
		all.add_all cc
		all.add_all bcc

		var proc = new ProcessWriter("sendmail", all.join(","))
		if proc.is_writable then proc.write to_s
		proc.close
		proc.wait
		var status = proc.status
		return status == 0
	end

	redef fun to_s
	do
		# Set encoding (and encode if needed)
		var content = content
		var encoding
		if encrypt_with_base64 then
			content = content.encode_base64
			encoding = "base64"
		else
			encoding = "8bit"
		end
		header["Content-Transfer-Encoding"] = encoding

		# Generate expected format
		return """
From: {{{from}}}\r
To: {{{to.join(",")}}}\r
CC: {{{cc.join(",")}}}\r
BCC: {{{bcc.join(",")}}}\r
Subject: {{{subject}}}\r
{{{header.join("\r\n", ": ")}}}\r\n\r
{{{content}}}"""
	end
end
lib/sendmail/sendmail.nit:34,1--108,3