mirror of
https://github.com/discourse/discourse.git
synced 2025-06-01 01:24:48 +08:00
FEATURE: Add attachments to outgoing emails
This feature is off by default and can can be configured with the `email_total_attachment_size_limit_kb` site setting. Co-authored-by: Maja Komel <maja.komel@gmail.com>
This commit is contained in:
@ -100,6 +100,8 @@ module Email
|
||||
# guards against deleted posts
|
||||
return skip(SkippedEmailLog.reason_types[:sender_post_deleted]) unless post
|
||||
|
||||
add_attachments(post)
|
||||
|
||||
topic = post.topic
|
||||
first_post = topic.ordered_posts.first
|
||||
|
||||
@ -239,6 +241,38 @@ module Email
|
||||
|
||||
private
|
||||
|
||||
def add_attachments(post)
|
||||
max_email_size = SiteSetting.email_total_attachment_size_limit_kb.kilobytes
|
||||
return if max_email_size == 0
|
||||
|
||||
email_size = 0
|
||||
post.uploads.each do |upload|
|
||||
next if FileHelper.is_supported_image?(upload.original_filename)
|
||||
next if email_size + upload.filesize > max_email_size
|
||||
|
||||
begin
|
||||
path = if upload.local?
|
||||
Discourse.store.path_for(upload)
|
||||
else
|
||||
Discourse.store.download(upload).path
|
||||
end
|
||||
|
||||
@message.attachments[upload.original_filename] = File.read(path)
|
||||
email_size += File.size(path)
|
||||
rescue => e
|
||||
Discourse.warn_exception(
|
||||
e,
|
||||
message: "Failed to attach file to email",
|
||||
env: {
|
||||
post_id: post.id,
|
||||
upload_id: upload.id,
|
||||
filename: upload.original_filename
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def header_value(name)
|
||||
header = @message.header[name]
|
||||
return nil unless header
|
||||
|
Reference in New Issue
Block a user