On 5 May 2017 at 19:01,  <[email protected]> wrote:
> Repository: incubator-ponymail
> Updated Branches:
>   refs/heads/master 2b8b5b0da -> c4e38edb4
>
>
> Detect and convert base64 blobs
>
> If the archiver has saved a source blob as base64,
> detect it and convert back to plain text when displaying.
> This addresses issue #371.

-1

This should be unnecessary, because the base64 is already decoded in
elastic.lua, see:

https://github.com/apache/incubator-ponymail/blob/master/site/api/lib/elastic.lua#L116

If that is not working, it should be fixed.

In any case, fixing source.lua is insufficient because mbox.lua also
reads mbox_source.

That is why the fix was added to elastic.lua instead.

>
> Project: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/repo
> Commit: 
> http://git-wip-us.apache.org/repos/asf/incubator-ponymail/commit/c4e38edb
> Tree: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/tree/c4e38edb
> Diff: http://git-wip-us.apache.org/repos/asf/incubator-ponymail/diff/c4e38edb
>
> Branch: refs/heads/master
> Commit: c4e38edb4032d1613fcff161be0a3bd201986a4a
> Parents: 2b8b5b0
> Author: Daniel Gruno <[email protected]>
> Authored: Fri May 5 20:01:28 2017 +0200
> Committer: Daniel Gruno <[email protected]>
> Committed: Fri May 5 20:01:28 2017 +0200
>
> ----------------------------------------------------------------------
>  site/api/source.lua | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/incubator-ponymail/blob/c4e38edb/site/api/source.lua
> ----------------------------------------------------------------------
> diff --git a/site/api/source.lua b/site/api/source.lua
> index 5de4dec..95dcc5f 100644
> --- a/site/api/source.lua
> +++ b/site/api/source.lua
> @@ -23,6 +23,18 @@ local user = require 'lib/user'
>  local cross = require 'lib/cross'
>  local utils = require 'lib/utils'
>
> +function is_base64(msg)
> +   -- base64 is always a multiple of 4
> +   if #msg % 4 == 0 then
> +      -- base64 only has a-zA-Z0-9+=/ in it
> +      if not msg:match("([^a-zA-Z0-9+=/])") then
> +         -- very likely base64 :)
> +         return true
> +      end
> +   end
> +   return false
> +end
> +
>  function handle(r)
>      -- content is currently utf-8, see #367
>      cross.contentType(r, "text/plain; charset=utf-8")
> @@ -46,6 +58,10 @@ function handle(r)
>          if aaa.canAccessDoc(r, doc, account) then
>              local doc_raw = elastic.get('mbox_source', doc.request_id)
>              if doc_raw then
> +                -- If this could be base64, try to convert it.
> +                if is_base64(doc_raw.source) then
> +                    pcall(function() doc_raw.source = 
> r:base64_decode(doc_raw.source) end)
> +                end
>                  r:puts(doc_raw.source)
>              else
>                  r:puts("Could not find the email source, sorry!")
>

Reply via email to