<?xml version="1.0" encoding="utf-8"?> 
<rss version="2.0"
  xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
  xmlns:atom="http://www.w3.org/2005/Atom">

<channel>

<title>IT science: заметки с тегом Perl</title>
<link>https://itscience.pro/tags/perl/</link>
<description>IT science — статьи и инструкции из мира IT</description>
<author></author>
<language>ru</language>
<generator>Aegea 11.4 (v4171)</generator>

<itunes:subtitle>IT science — статьи и инструкции из мира IT</itunes:subtitle>
<itunes:image href="" />
<itunes:explicit></itunes:explicit>

<item>
<title>лечим почтовые вложения winmail.dat</title>
<guid isPermaLink="false">30</guid>
<link>https://itscience.pro/all/lechim-pochtovye-vlozheniya-winmail-dat/</link>
<pubDate>Mon, 21 Dec 2020 11:47:09 +0300</pubDate>
<author></author>
<comments>https://itscience.pro/all/lechim-pochtovye-vlozheniya-winmail-dat/</comments>
<description>
&lt;p&gt;Проблема древняя и как водится связана с попыткой Microsoft навязывать свои стандарты. Откуда берется почтовое вложение winmail.dat вы можете почитать тут: &lt;a href="https://support.mozilla.org/ru/kb/chto-oznachaet-vlozhenie-winmaildat"&gt;https://support.mozilla.org/ru/kb/chto-oznachaet-vlozhenie-winmaildat&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;сегодня мы решим эту проблему глобально, прокачаем наш postfix сервер&lt;/p&gt;
&lt;ol start="1"&gt;
&lt;li&gt;Установим MIMEDefang.&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;для CentOS&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;yum install mimedefang&lt;/code&gt;&lt;/pre&gt;&lt;blockquote&gt;
&lt;p&gt;для Ubuntu&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;apt-get install mimedefang&lt;/code&gt;&lt;/pre&gt;&lt;ol start="2"&gt;
&lt;li&gt;Настроим MIMEDefang на определенный порт TCP, наша служба будет слушать этот порт. Для этого исправим конфигурацию&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;для CentOS: /etc/sysconfig/mimedefang&lt;br /&gt;
для Ubuntu: /etc/default/mimedefang&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;дописываем в конце&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;SOCKET=inet:10185&lt;/code&gt;&lt;/pre&gt;&lt;ol start="3"&gt;
&lt;li&gt;Отредактируем файл  &lt;b&gt;/etc/mail/mimedefang-filter&lt;/b&gt;, можете просто вставить текст ниже&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;# -*- Perl -*-
#***********************************************************************
#
# mimedefang-filter
#
# Suggested minimum-protection filter for Microsoft Windows clients, plus
# SpamAssassin checks if SpamAssassin is installed.
#
# Copyright (C) 2002 Roaring Penguin Software Inc.
#
# This program may be distributed under the terms of the GNU General
# Public License, Version 2, or (at your option) any later version.
#
# $Id$
#***********************************************************************

#***********************************************************************
# Set administrator&amp;#039;s e-mail address here.  The administrator receives
# quarantine messages and is listed as the contact for site-wide
# MIMEDefang policy.  A good example would be &amp;#039;defang-admin@mydomain.com&amp;#039;
#***********************************************************************
$AdminAddress = &amp;#039;postmaster@localhost&amp;#039;;
$AdminName = &amp;quot;MIMEDefang Administrator&amp;#039;s Full Name&amp;quot;;

#***********************************************************************
# Set the e-mail address from which MIMEDefang quarantine warnings and
# user notifications appear to come.  A good example would be
# &amp;#039;mimedefang@mydomain.com&amp;#039;.  Make sure to have an alias for this
# address if you want replies to it to work.
#***********************************************************************
$DaemonAddress = &amp;#039;mimedefang@localhost&amp;#039;;

#***********************************************************************
# If you set $AddWarningsInline to 1, then MIMEDefang tries *very* hard
# to add warnings directly in the message body (text or html) rather
# than adding a separate &amp;quot;WARNING.TXT&amp;quot; MIME part.  If the message
# has no text or html part, then a separate MIME part is still used.
#***********************************************************************
$AddWarningsInline = 0;

#***********************************************************************
# To enable syslogging of virus and spam activity, add the following
# to the filter:
# md_graphdefang_log_enable();
# You may optionally provide a syslogging facility by passing an
# argument such as:  md_graphdefang_log_enable(&amp;#039;local4&amp;#039;);  If you do this, be
# sure to setup the new syslog facility (probably in /etc/syslog.conf).
# An optional second argument causes a line of output to be produced
# for each recipient (if it is 1), or only a single summary line
# for all recipients (if it is 0.)  The default is 1.
# Comment this line out to disable logging.
#***********************************************************************
md_graphdefang_log_enable(&amp;#039;mail&amp;#039;, 1);

#***********************************************************************
# Uncomment this to block messages with more than 50 parts.  This will
# *NOT* work unless you&amp;#039;re using Roaring Penguin&amp;#039;s patched version
# of MIME tools, version MIME-tools-5.411a-RP-Patched-02 or later.
#
# WARNING: DO NOT SET THIS VARIABLE unless you&amp;#039;re using at least
# MIME-tools-5.411a-RP-Patched-02; otherwise, your filter will fail.
#***********************************************************************
# $MaxMIMEParts = 50;

#***********************************************************************
# Set various stupid things your mail client does below.
#***********************************************************************

# Set the next one if your mail client cannot handle multiple &amp;quot;inline&amp;quot;
# parts.
$Stupidity{&amp;quot;NoMultipleInlines&amp;quot;} = 0;

# Detect and load Perl modules
detect_and_load_perl_modules();


sub filter {
    my($entity, $fname, $ext, $type) = @_;
 
    ### Convert TNEF winmail.dat format
    ### Note: You must install Convert::TNEF and File::Type from CPAN before using this script
    if (lc($type) eq &amp;quot;application/ms-tnef&amp;quot; or lc($fname) eq &amp;quot;winmail.dat&amp;quot; ) {
        use Convert::TNEF;
        use File::Type;
        use File::Temp qw(tempfile tempdir);
 
        # Create a unique temporary directory under &amp;quot;/tmp&amp;quot;
        my $tnefdir = tempdir(CLEANUP =&amp;gt; 1, DIR =&amp;gt; &amp;quot;/tmp&amp;quot;);
        if (not $tnefdir) {
                md_graphdefang_log(&amp;#039;tnef_fail&amp;#039;,&amp;quot;Unable to create temporary directory&amp;quot;);
                return action_accept();
        }
 
        # If we can&amp;#039;t Convert the TNEF file for some reason, just accept the attachment and log the error
        my $tnef = Convert::TNEF-&amp;gt;read_ent($entity,{output_dir=&amp;gt;&amp;quot;$tnefdir&amp;quot;});
        if (not $tnef) {
                md_graphdefang_log(&amp;#039;tnef_fail&amp;#039;,$Convert::TNEF::errstr);
                return action_accept();
        }
 
        my $ft = File::Type-&amp;gt;new();
 
        # Append attachments contained in the winmail.dat file to the message.
        for ($tnef-&amp;gt;attachments) {
             # Determine the mime-type of the file
             my $mimetype = $ft-&amp;gt;mime_type($_-&amp;gt;data);
 
                # File::Type doesn&amp;#039;t detect text files well, this is a workaround
             if ($mimetype eq &amp;quot;application/octet-stream&amp;quot;) {
                  #Set the mime-type to text/plain if the first 1024 characters are printable
                  $text_check = substr($_-&amp;gt;data,0,1024);
                  $mimetype = &amp;quot;text/plain&amp;quot; unless $text_check =~ /[^[:print:]s]/;
             }
 
             my $tnef_entity = action_add_part($entity, &amp;quot;$mimetype&amp;quot;, &amp;quot;base64&amp;quot;, $_-&amp;gt;data, $_-&amp;gt;longname, &amp;quot;attachment&amp;quot;);
             md_graphdefang_log(&amp;#039;tnef_ext&amp;#039;, &amp;quot;File: &amp;quot; . $_-&amp;gt;longname . &amp;quot; Type: $mimetype&amp;quot;);
 
             # Run each new TNEF-sourced MIME part back through the filter again, this ensures that bad filenames etc.
             # cannot sneak through by being contained in winmail.dat files
 
             filter ($tnef_entity, $_-&amp;gt;longname, &amp;quot;&amp;quot;, &amp;quot;$mimetype&amp;quot;);
        }
 
        # Deletes working files
        $tnef-&amp;gt;purge;

 
        # Remark this if you want still want to keep the original winmail.dat file
        return action_drop();
    }
 
    # Keep the attachment
    return action_accept();
}

# DO NOT delete the next line, or Perl will complain.
1;&lt;/code&gt;&lt;/pre&gt;&lt;ol start="4"&gt;
&lt;li&gt;Установим модели Perl  &lt;b&gt;Convert::TNEF&lt;/b&gt; и &lt;b&gt;File::Type&lt;/b&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;для CentOS&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;yum install perl-Convert-TNEF.noarch&lt;/code&gt;&lt;/pre&gt;&lt;blockquote&gt;
&lt;p&gt;второй пакет надо скачать и установить&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;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&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;yum install perl-File-Type-0.22-1.el6.rf.noarch.rpm&lt;/code&gt;&lt;/pre&gt;&lt;blockquote&gt;
&lt;p&gt;для Ubuntu&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;apt-get install libconvert-tnef-perl&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;apt-get install libfile-type-perl&lt;/code&gt;&lt;/pre&gt;&lt;ol start="5"&gt;
&lt;li&gt;Проверим синтаксис Perl&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;# perl -c /etc/mail/mimedefang-filter&lt;/code&gt;&lt;/pre&gt;&lt;ol start="6"&gt;
&lt;li&gt;Настроим автозапуск службы MIMEDefang и запустим ее&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;systemctl enable mimedefang.service&lt;/code&gt;&lt;/pre&gt;&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;service mimedefang restart&lt;/code&gt;&lt;/pre&gt;&lt;ol start="7"&gt;
&lt;li&gt;Проверим, слушает ли сервис указанный выше порт&lt;/li&gt;
&lt;/ol&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;# netstat -tlpn | grep 10185
tcp        0      0 0.0.0.0:10185           0.0.0.0:*               LISTEN      7401/mimedefang&lt;/code&gt;&lt;/pre&gt;&lt;ol start="8"&gt;
&lt;li&gt;Теперь добавим проверку в Postfix, для этого откроем конфиг &lt;b&gt;/etc/postfic/main.cf&lt;/b&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;blockquote&gt;
&lt;p&gt;и допишем в конце&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class="e2-text-code"&gt;&lt;code class=""&gt;smtpd_milters = inet:localhost:10185
milter_default_action = accept&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;готово! Любое письмо, которое будет иметь во вложении winmail.dat, будет обработано нашей службой и вложение будет расшифровано!&lt;/p&gt;
</description>
</item>


</channel>
</rss>