{
    "version": "https:\/\/jsonfeed.org\/version\/1.1",
    "title": "IT science: заметки с тегом Perl",
    "_rss_description": "IT science — статьи и инструкции из мира IT",
    "_rss_language": "ru",
    "_itunes_email": "",
    "_itunes_categories_xml": "",
    "_itunes_image": "",
    "_itunes_explicit": "",
    "home_page_url": "https:\/\/itscience.pro\/tags\/perl\/",
    "feed_url": "https:\/\/itscience.pro\/tags\/perl\/json\/",
    "icon": "https:\/\/itscience.pro\/pictures\/userpic\/userpic@2x.jpg?1658757154",
    "authors": [
        {
            "name": "IT science",
            "url": "https:\/\/itscience.pro\/",
            "avatar": "https:\/\/itscience.pro\/pictures\/userpic\/userpic@2x.jpg?1658757154"
        }
    ],
    "items": [
        {
            "id": "30",
            "url": "https:\/\/itscience.pro\/all\/lechim-pochtovye-vlozheniya-winmail-dat\/",
            "title": "лечим почтовые вложения winmail.dat",
            "content_html": "<p>Проблема древняя и как водится связана с попыткой Microsoft навязывать свои стандарты. Откуда берется почтовое вложение winmail.dat вы можете почитать тут: <a href=\"https:\/\/support.mozilla.org\/ru\/kb\/chto-oznachaet-vlozhenie-winmaildat\">https:\/\/support.mozilla.org\/ru\/kb\/chto-oznachaet-vlozhenie-winmaildat<\/a><\/p>\n<p>сегодня мы решим эту проблему глобально, прокачаем наш postfix сервер<\/p>\n<ol start=\"1\">\n<li>Установим MIMEDefang.<\/li>\n<\/ol>\n<blockquote>\n<p>для CentOS<\/p>\n<\/blockquote>\n<pre class=\"e2-text-code\"><code class=\"\">yum install mimedefang<\/code><\/pre><blockquote>\n<p>для Ubuntu<\/p>\n<\/blockquote>\n<pre class=\"e2-text-code\"><code class=\"\">apt-get install mimedefang<\/code><\/pre><ol start=\"2\">\n<li>Настроим MIMEDefang на определенный порт TCP, наша служба будет слушать этот порт. Для этого исправим конфигурацию<\/li>\n<\/ol>\n<blockquote>\n<p>для CentOS: \/etc\/sysconfig\/mimedefang<br \/>\nдля Ubuntu: \/etc\/default\/mimedefang<\/p>\n<\/blockquote>\n<blockquote>\n<p>дописываем в конце<\/p>\n<\/blockquote>\n<pre class=\"e2-text-code\"><code class=\"\">SOCKET=inet:10185<\/code><\/pre><ol start=\"3\">\n<li>Отредактируем файл  <b>\/etc\/mail\/mimedefang-filter<\/b>, можете просто вставить текст ниже<\/li>\n<\/ol>\n<pre class=\"e2-text-code\"><code class=\"\"># -*- Perl -*-\n#***********************************************************************\n#\n# mimedefang-filter\n#\n# Suggested minimum-protection filter for Microsoft Windows clients, plus\n# SpamAssassin checks if SpamAssassin is installed.\n#\n# Copyright (C) 2002 Roaring Penguin Software Inc.\n#\n# This program may be distributed under the terms of the GNU General\n# Public License, Version 2, or (at your option) any later version.\n#\n# $Id$\n#***********************************************************************\n\n#***********************************************************************\n# Set administrator&#039;s e-mail address here.  The administrator receives\n# quarantine messages and is listed as the contact for site-wide\n# MIMEDefang policy.  A good example would be &#039;defang-admin@mydomain.com&#039;\n#***********************************************************************\n$AdminAddress = &#039;postmaster@localhost&#039;;\n$AdminName = &quot;MIMEDefang Administrator&#039;s Full Name&quot;;\n\n#***********************************************************************\n# Set the e-mail address from which MIMEDefang quarantine warnings and\n# user notifications appear to come.  A good example would be\n# &#039;mimedefang@mydomain.com&#039;.  Make sure to have an alias for this\n# address if you want replies to it to work.\n#***********************************************************************\n$DaemonAddress = &#039;mimedefang@localhost&#039;;\n\n#***********************************************************************\n# If you set $AddWarningsInline to 1, then MIMEDefang tries *very* hard\n# to add warnings directly in the message body (text or html) rather\n# than adding a separate &quot;WARNING.TXT&quot; MIME part.  If the message\n# has no text or html part, then a separate MIME part is still used.\n#***********************************************************************\n$AddWarningsInline = 0;\n\n#***********************************************************************\n# To enable syslogging of virus and spam activity, add the following\n# to the filter:\n# md_graphdefang_log_enable();\n# You may optionally provide a syslogging facility by passing an\n# argument such as:  md_graphdefang_log_enable(&#039;local4&#039;);  If you do this, be\n# sure to setup the new syslog facility (probably in \/etc\/syslog.conf).\n# An optional second argument causes a line of output to be produced\n# for each recipient (if it is 1), or only a single summary line\n# for all recipients (if it is 0.)  The default is 1.\n# Comment this line out to disable logging.\n#***********************************************************************\nmd_graphdefang_log_enable(&#039;mail&#039;, 1);\n\n#***********************************************************************\n# Uncomment this to block messages with more than 50 parts.  This will\n# *NOT* work unless you&#039;re using Roaring Penguin&#039;s patched version\n# of MIME tools, version MIME-tools-5.411a-RP-Patched-02 or later.\n#\n# WARNING: DO NOT SET THIS VARIABLE unless you&#039;re using at least\n# MIME-tools-5.411a-RP-Patched-02; otherwise, your filter will fail.\n#***********************************************************************\n# $MaxMIMEParts = 50;\n\n#***********************************************************************\n# Set various stupid things your mail client does below.\n#***********************************************************************\n\n# Set the next one if your mail client cannot handle multiple &quot;inline&quot;\n# parts.\n$Stupidity{&quot;NoMultipleInlines&quot;} = 0;\n\n# Detect and load Perl modules\ndetect_and_load_perl_modules();\n\n\nsub filter {\n    my($entity, $fname, $ext, $type) = @_;\n \n    ### Convert TNEF winmail.dat format\n    ### Note: You must install Convert::TNEF and File::Type from CPAN before using this script\n    if (lc($type) eq &quot;application\/ms-tnef&quot; or lc($fname) eq &quot;winmail.dat&quot; ) {\n        use Convert::TNEF;\n        use File::Type;\n        use File::Temp qw(tempfile tempdir);\n \n        # Create a unique temporary directory under &quot;\/tmp&quot;\n        my $tnefdir = tempdir(CLEANUP =&gt; 1, DIR =&gt; &quot;\/tmp&quot;);\n        if (not $tnefdir) {\n                md_graphdefang_log(&#039;tnef_fail&#039;,&quot;Unable to create temporary directory&quot;);\n                return action_accept();\n        }\n \n        # If we can&#039;t Convert the TNEF file for some reason, just accept the attachment and log the error\n        my $tnef = Convert::TNEF-&gt;read_ent($entity,{output_dir=&gt;&quot;$tnefdir&quot;});\n        if (not $tnef) {\n                md_graphdefang_log(&#039;tnef_fail&#039;,$Convert::TNEF::errstr);\n                return action_accept();\n        }\n \n        my $ft = File::Type-&gt;new();\n \n        # Append attachments contained in the winmail.dat file to the message.\n        for ($tnef-&gt;attachments) {\n             # Determine the mime-type of the file\n             my $mimetype = $ft-&gt;mime_type($_-&gt;data);\n \n                # File::Type doesn&#039;t detect text files well, this is a workaround\n             if ($mimetype eq &quot;application\/octet-stream&quot;) {\n                  #Set the mime-type to text\/plain if the first 1024 characters are printable\n                  $text_check = substr($_-&gt;data,0,1024);\n                  $mimetype = &quot;text\/plain&quot; unless $text_check =~ \/[^[:print:]s]\/;\n             }\n \n             my $tnef_entity = action_add_part($entity, &quot;$mimetype&quot;, &quot;base64&quot;, $_-&gt;data, $_-&gt;longname, &quot;attachment&quot;);\n             md_graphdefang_log(&#039;tnef_ext&#039;, &quot;File: &quot; . $_-&gt;longname . &quot; Type: $mimetype&quot;);\n \n             # Run each new TNEF-sourced MIME part back through the filter again, this ensures that bad filenames etc.\n             # cannot sneak through by being contained in winmail.dat files\n \n             filter ($tnef_entity, $_-&gt;longname, &quot;&quot;, &quot;$mimetype&quot;);\n        }\n \n        # Deletes working files\n        $tnef-&gt;purge;\n\n \n        # Remark this if you want still want to keep the original winmail.dat file\n        return action_drop();\n    }\n \n    # Keep the attachment\n    return action_accept();\n}\n\n# DO NOT delete the next line, or Perl will complain.\n1;<\/code><\/pre><ol start=\"4\">\n<li>Установим модели Perl  <b>Convert::TNEF<\/b> и <b>File::Type<\/b><\/li>\n<\/ol>\n<blockquote>\n<p>для CentOS<\/p>\n<\/blockquote>\n<pre class=\"e2-text-code\"><code class=\"\">yum install perl-Convert-TNEF.noarch<\/code><\/pre><blockquote>\n<p>второй пакет надо скачать и установить<\/p>\n<\/blockquote>\n<pre class=\"e2-text-code\"><code class=\"\">wget https:\/\/ftp.tu-chemnitz.de\/pub\/linux\/dag\/redhat\/el6\/en\/x86_64\/rpmforge\/RPMS\/perl-File-Type-0.22-1.el6.rf.noarch.rpm<\/code><\/pre><pre class=\"e2-text-code\"><code class=\"\">yum install perl-File-Type-0.22-1.el6.rf.noarch.rpm<\/code><\/pre><blockquote>\n<p>для Ubuntu<\/p>\n<\/blockquote>\n<pre class=\"e2-text-code\"><code class=\"\">apt-get install libconvert-tnef-perl<\/code><\/pre><pre class=\"e2-text-code\"><code class=\"\">apt-get install libfile-type-perl<\/code><\/pre><ol start=\"5\">\n<li>Проверим синтаксис Perl<\/li>\n<\/ol>\n<pre class=\"e2-text-code\"><code class=\"\"># perl -c \/etc\/mail\/mimedefang-filter<\/code><\/pre><ol start=\"6\">\n<li>Настроим автозапуск службы MIMEDefang и запустим ее<\/li>\n<\/ol>\n<pre class=\"e2-text-code\"><code class=\"\">systemctl enable mimedefang.service<\/code><\/pre><pre class=\"e2-text-code\"><code class=\"\">service mimedefang restart<\/code><\/pre><ol start=\"7\">\n<li>Проверим, слушает ли сервис указанный выше порт<\/li>\n<\/ol>\n<pre class=\"e2-text-code\"><code class=\"\"># netstat -tlpn | grep 10185\ntcp        0      0 0.0.0.0:10185           0.0.0.0:*               LISTEN      7401\/mimedefang<\/code><\/pre><ol start=\"8\">\n<li>Теперь добавим проверку в Postfix, для этого откроем конфиг <b>\/etc\/postfic\/main.cf<\/b><\/li>\n<\/ol>\n<blockquote>\n<p>и допишем в конце<\/p>\n<\/blockquote>\n<pre class=\"e2-text-code\"><code class=\"\">smtpd_milters = inet:localhost:10185\nmilter_default_action = accept<\/code><\/pre><p>готово! Любое письмо, которое будет иметь во вложении winmail.dat, будет обработано нашей службой и вложение будет расшифровано!<\/p>\n",
            "date_published": "2020-12-21T11:47:09+03:00",
            "date_modified": "2020-12-21T11:46:58+03:00",
            "tags": [
                "MIMEDefang",
                "Perl",
                "Postfix",
                "winmail.dat"
            ],
            "_date_published_rfc2822": "Mon, 21 Dec 2020 11:47:09 +0300",
            "_rss_guid_is_permalink": "false",
            "_rss_guid": "30",
            "_e2_data": {
                "is_favourite": false,
                "links_required": [
                    "highlight\/highlight.js",
                    "highlight\/highlight.css"
                ],
                "og_images": []
            }
        }
    ],
    "_e2_version": 4171,
    "_e2_ua_string": "Aegea 11.4 (v4171)"
}