mime-0.4.4/ 0000755 0000041 0000041 00000000000 13126650165 012503 5 ustar www-data www-data mime-0.4.4/Rakefile 0000644 0000041 0000041 00000001120 13126650165 014142 0 ustar www-data www-data require 'rdoc/task'
require 'rubygems/package_task'
require 'rake/testtask'
Gem::PackageTask.new(eval File.read('mime.gemspec')) do |pkg|
pkg.need_tar_gz = true
end
RDoc::Task.new do |rdoc|
rdoc.main = 'README.rdoc'
rdoc.rdoc_dir = 'doc'
rdoc.rdoc_files.include('README.rdoc', 'lib/')
rdoc.options << "--all"
end
Rake::TestTask.new do |t|
t.warning = true
end
desc 'Upload RDoc HTML files to server'
task :upload_rdoc => :rdoc do
%x[
rdir=/var/www/sites/ecentryx.com/public/gems/mime
rsvr=hercules
cd ./doc && pax -w . | ssh $rsvr "cd $rdir && rm -rf ./*; pax -r"
]
end
mime-0.4.4/mime.gemspec 0000644 0000041 0000041 00000001374 13126650165 015004 0 ustar www-data www-data version = File.read('./lib/mime.rb')[/VERSION = '(.*)'/, 1]
Gem::Specification.new('mime', version) do |s|
s.author = 'Clint Pachl'
s.email = 'pachl@ecentryx.com'
s.homepage = 'https://ecentryx.com/gems/mime'
s.license = 'ISC'
s.summary = 'Multipurpose Internet Mail Extensions (MIME) Library'
s.description = <<-EOF
A library for building RFC compliant Multipurpose Internet Mail Extensions
(MIME) messages. It can be used to construct standardized MIME messages for use
in client/server communications, such as Internet mail or HTTP
multipart/form-data transactions.
EOF
s.files = Dir['README.rdoc', 'Rakefile', 'mime.gemspec',
'lib/**/*.rb', 'test/**/*']
s.test_files = Dir['test/*.rb']
end
mime-0.4.4/README.rdoc 0000644 0000041 0000041 00000034035 13126650165 014316 0 ustar www-data www-data == Multipurpose Internet Mail Extensions (MIME)
A library for building RFC compliant Multipurpose Internet Mail Extensions
(MIME) messages. It can be used to construct standardized MIME messages for use
in client/server communications, such as Internet mail or HTTP
multipart/form-data transactions.
== See Also
* MIME for RFCs used to implement the library (other RFCs scattered throughout)
* MIME::CompositeMedia for a description of composite media types
* MIME::DiscreteMedia for a description of discrete media types
* MIME::DiscreteMediaFactory for easy programming of discrete media types
* MIME::ContentFormats for ways to encode/decode discrete media types
== Media Inheritance Heirarchy
Media*
^
|
|--DiscreteMedia*
| ^
| |
| |--Application
| |--Audio
| |--Image
| |--Text
| +--Video
|
+--CompositeMedia*
^
|
|--Message**
| ^
| |
| |--ExternalBody**
| |--Partial**
| +--RFC822**
|
+--Multipart*
^
|
|--Alternative
|--Digest**
|--Encrypted**
|--FormData
|--Mixed
|--Parallel**
|--Related
|--Report**
+--Signed**
* Abstract Class
** Not implemented
== MIME Message Format
________________ -------------------+
| | |
| RFC822 & MIME | |
| Headers | |
|________________| |
________________ |
| | |
| MIME Headers | |
|~~~~~~~~~~~~~~~~| <-- MIME Entity* |--- RFC822/MIME
| Body* | (N) | Message
|________________| |
________________ |
| | |
| MIME Headers | |
|~~~~~~~~~~~~~~~~| <-- MIME Entity* |
| Body* | (N+1) |
|________________| |
-------------------+
* Optional
Each MIME Entity must be a discrete (MIME::DiscreteMedia) or
composite (MIME::CompositeMedia) media type. Because MIME is recursive,
composite entity bodies may contain other composite or discrete entities and so
on. However, discrete entities are non-recursive and contain only non-MIME
bodies.
== Examples
First things first!
require 'mime'
include MIME # allow ommision of "MIME::" namespace in examples below
=== Instantiate a DiscreteMedia object
Discrete media objects, such as text or video, can be created directly using a
specific discrete media *class* or indirectly via the *factory*. If the media is
file backed, like the example below, the factory will open and read the data
file and determine the MIME type for you.
file = '/tmp/data.xml'
text_media = Text.new(File.read(file), 'xml') # media class
text_media = DiscreteMediaFactory.create(file) # media factory
Discrete media objects can then be embedded in MIME messages as we will see in
the next example.
=== Simple text/plain RFC822 email message
Create a well-formed email message with multiple recipients. The string
representation of the message (i.e. to_s) can then be sent directly via an
SMTP client.
msg = Mail.new # blank message with current date and message ID headers
msg.date -= 3600 # change date to 1 hour ago
msg.subject = 'This is important' # add subject
msg.headers.set('Priority', 'urgent') # add custom header
msg.body = Text.new('hello, world!', 'plain', 'charset' => 'us-ascii')
#
# The previous line is equivalent to the following snippet:
#
# msg.body = 'hello, world!'
# msg.headers.set('Content-Type', 'text/plain; charset=us-ascii')
msg.from = {'boss@example.com' => 'Boss Man'} # mailbox hash
msg.bcc = 'boss+home@example.com' # mailbox string
msg.cc = %w(secretary@example.com manager@example.com) # mailbox array
msg.to = {
'list@example.com' => nil, # no name display
'john@example.com' => 'John Doe',
'jane@example.com' => 'Jane Doe',
}
msg.to_s # ready to be sent via SMTP
=== RFC822 email message with image body
Embedding a single image within an email message requires a single discrete
media image. However, embedding multiple images requires a multipart/mixed
composite media type to encapsulate all of the discrete media images.
==== Email body with single image
img = Image.new(File.read('screenshot.png'), 'png')
img.disposition = 'inline'
img.description = 'My screenshot'
email = Mail.new(img)
==== Email body with multiple images
msg = Multipart::Mixed.new
msg.inline Image.new(File.read('screenshot1.png'), 'png')
msg.inline Image.new(File.read('screenshot2.png'), 'png')
msg.description = 'My screenshots'
email = Mail.new(msg)
=== Plain text multipart/mixed message with a file attachment
The multipart/mixed content type can be used to aggregate multiple unrelated
entities, such as text and an image.
text = DiscreteMediaFactory.create('/tmp/data.txt')
image = DiscreteMediaFactory.create('/tmp/ruby.png')
mixed_msg = Multipart::Mixed.new
mixed_msg.add(text)
mixed_msg.attach(image)
mixed_msg.to_s
=== Plain text and HTML multipart/alternative MIME message
The multipart/alternative content type allows for multiple, alternatively
formatted versions of the same content, such as plain text and HTML. Clients are
then responsible for choosing the most suitable version for display.
text_msg = Text.new(<
Hello, world!
Ruby is cool!