mailgun-ruby 1.1.4 → 1.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f7a3d2306cc5f23a9f5b198bbcef7767be64f1bc
4
- data.tar.gz: aa73b428690d284c293a89e848359a9f7617476a
3
+ metadata.gz: 55f7b59eef02feab663dbffa1a3da56692c37737
4
+ data.tar.gz: 2d6ad04ff6ee6607554fcffea4453bb751a0162a
5
5
  SHA512:
6
- metadata.gz: 56e7617f35b16862fee5b06a428d45925447edb12f1d721fdc87e8c382b8db140f40d1de4a5c63de59c96904e1f4322c80097aac7dc3cab838dc2d945922ab42
7
- data.tar.gz: ce165c6784831eed9240ef7b51b3ba855bea5066a5b294cbf3450eef321ddc33dd3d879d477b7c23cb8f80f4ac02f9125e26e3432f2273f69ec68ab9483aa928
6
+ metadata.gz: 70292ac10f56e185894bf288861c861dcb16a03157bba9fe6bb4498f074ad56521fbe8ced7d2b609275742650293304fd26f3ec276fcca7f103e3e6d030c1c7c
7
+ data.tar.gz: 919717c8e88c1d8671be798a9ce53c4db246dd11927b74d0bb555b6bc2b34c00315c13337570197a7fdf2b84e13f9d2550013abd15e04574ec2f1e7df9f58c96
@@ -117,7 +117,7 @@ module Mailgun
117
117
 
118
118
  # Adds a series of attachments, when called upon.
119
119
  #
120
- # @param [String] attachment A file object for attaching as an attachment.
120
+ # @param [String|File] attachment A file object for attaching as an attachment.
121
121
  # @param [String] filename The filename you wish the attachment to be.
122
122
  # @return [void]
123
123
  def add_attachment(attachment, filename = nil)
@@ -126,7 +126,7 @@ module Mailgun
126
126
 
127
127
  # Adds an inline image to the mesage object.
128
128
  #
129
- # @param [String] inline_image A file object for attaching an inline image.
129
+ # @param [String|File] inline_image A file object for attaching an inline image.
130
130
  # @param [String] filename The filename you wish the inline image to be.
131
131
  # @return [void]
132
132
  def add_inline_image(inline_image, filename = nil)
@@ -381,7 +381,7 @@ module Mailgun
381
381
  # Private: Adds a file to the message.
382
382
  #
383
383
  # @param [Symbol] disposition The type of file: :attachment or :inline
384
- # @param [String] attachment A file object for attaching as an attachment.
384
+ # @param [String|File] attachment A file object for attaching as an attachment.
385
385
  # @param [String] filename The filename you wish the attachment to be.
386
386
  # @return [void]
387
387
  #
@@ -1,4 +1,4 @@
1
1
  # It's the version. Yeay!
2
2
  module Mailgun
3
- VERSION = '1.1.4'
3
+ VERSION = '1.1.5'
4
4
  end
@@ -2,20 +2,55 @@ module Railgun
2
2
 
3
3
  class Attachment < StringIO
4
4
 
5
- attr_reader :source_filename, :content_type, :path
5
+ attr_reader :filename, :content_type, :path,
6
+ :original_filename, :overwritten_filename
6
7
 
7
8
  def initialize(attachment, *args)
8
9
  @path = ''
9
- if args.detect { |opt| opt[:inline] }
10
- basename = @source_filename = attachment.cid
10
+ @inline = args.detect { |opt| opt[:inline] }
11
+
12
+ if @inline
13
+ @filename = attachment.cid
11
14
  else
12
- basename = @source_filename = attachment.filename
15
+ @filename = attachment.filename
13
16
  end
14
17
 
18
+ @original_filename = @filename
19
+
20
+ if args.detect { |opt| opt[:filename] }
21
+ @filename = opt[:filename]
22
+ end
23
+
24
+ @overwritten_filename = @filename
25
+
15
26
  @content_type = attachment.content_type.split(';')[0]
16
27
 
17
28
  super attachment.body.decoded
18
29
  end
19
30
 
31
+ def inline?
32
+ @inline
33
+ end
34
+
35
+ def is_original_filename
36
+ @original_filename == @overwritten_filename
37
+ end
38
+
39
+ def source_filename
40
+ @filename
41
+ end
42
+
43
+ def attach_to_message!(mb)
44
+ if mb.nil?
45
+ nil
46
+ end
47
+
48
+ if inline?
49
+ mb.add_inline_image self, @filename
50
+ else
51
+ mb.add_attachment self, @filename
52
+ end
53
+ end
54
+
20
55
  end
21
56
  end
@@ -119,11 +119,8 @@ module Railgun
119
119
  return mb.message if mail.attachments.empty?
120
120
 
121
121
  mail.attachments.each do |attach|
122
- if attach.inline?
123
- mb.add_inline_image Attachment.new(attach, encoding: 'ascii-8bit', inline: true)
124
- else
125
- mb.add_attachment Attachment.new(attach, encoding: 'ascii-8bit')
126
- end
122
+ attach = Attachment.new(attach, encoding: 'ascii-8bit', inline: attach.inline?)
123
+ attach.attach_to_message! mb
127
124
  end
128
125
 
129
126
  return mb.message
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mailgun-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mailgun
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-02-18 00:00:00.000000000 Z
12
+ date: 2017-02-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler