<?xml version="1.0"?>
<!--
 -
 -  $Id$
 -
 -  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
 -  project.
 -
 -  Copyright (C) 1998-2018 OpenLink Software
 -
 -  This project is free software; you can redistribute it and/or modify it
 -  under the terms of the GNU General Public License as published by the
 -  Free Software Foundation; only version 2 of the License, dated June 1991.
 -
 -  This program is distributed in the hope that it will be useful, but
 -  WITHOUT ANY WARRANTY; without even the implied warranty of
 -  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 -  General Public License for more details.
 -
 -  You should have received a copy of the GNU General Public License along
 -  with this program; if not, write to the Free Software Foundation, Inc.,
 -  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 -
-->
<v:page name="moblogimg"
        xmlns:v="http://www.openlinksw.com/vspx/"
        doctype="-//W3C//DTD XHTML 1.0 Transitional//EN"
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
        on-deadlock-retry="5">
  <?vsp
    declare _blogid, _sid, _mid, _realm, _blog_access, scale any;
    _blogid := get_keyword('blogid', params);
    _sid := get_keyword('sid', params);
    _mid := get_keyword('mid', params);
    _realm := get_keyword('realm', params);
    scale := atoi(get_keyword('scale', params, '0'));
    _blog_access := BLOG2_GET_ACCESS(_blogid, _sid, _realm);
    http_rewrite();
    if(_blog_access = 0) {
      http_header('Content-Type: text/plain\r\n');
      http('You have no access to this blog...');
      goto end_block;
    }
    declare rc any;
    declare content, file, mime, content1 varchar;
    whenever not found goto not_founded;
    select
      MA_CONTENT,
      MA_MIME
    into
      content,
      mime
    from
      MAIL_ATTACHMENT
    where
      MA_ID = _mid and
    MA_BLOG_ID = _blogid;
    http_header(sprintf ('Content-Type: %s\r\n', mime));
    if (scale > 0)
      {
        content1 := BLOG2_MAKE_THUMB (content, mime, scale);
        http(cast (content1 as varchar));
      }
    else
      http (content);
    goto end_block;
not_founded:
    http_header('Content-Type: text/plain\r\n');
    http('Resource not found...');
end_block:;
  ?>
</v:page>
