Pošta

Marcel Kolaja <ace@mail.muni.cz>


Obsah


Úvod

Elektronická pošta je forma neinteraktivní komunikace. V roce 1982 byl v RFC 821 definován protokol SMTP (Simple Mail Transfer Protocol), standard pro přenos elektronické pošty. V roce 1995 bylo sepsáno RFC 1869, které definuje některá rozšíření tohoto protokolu (známo též pod názvem ESMTP -- Extended Simple Mail Transfer Protocol). Programy použité při komunikaci elektronickou poštou dělíme do dvou základních kategorií: MTA (Mail Transfer Agent), program pro přenos zpráv po síti, a MUA (Mail User Agent), program (ne)přinášející uživateli komfort při čtení a posílání pošty. V roce 1982 byl v RFC 822 definován formát zpráv. Podle tohoto standardu zpráva začíná hlavičkami a pokračuje tělem. V hlavičce Date: obsahující datum a čas odeslání zprávy bylo dovoleno označení roku pouze posledním dvojčíslím, což byl problém Y2K, proto byl v RFC 1123 vydaném v roce 1989 doporučen zápis roku čtyřčíslím. Formát zpráv pak rozšiřuje MIME (Multipurpose Internet Mail Extensions) v RFC 1521, RFC 2045, RFC 2046, RFC 2047, RFC 2048, RFC 2049 a RFC 2231. V roce 2001 bylo RFC 821 nahrazeno RFC 2821 a podobně RFC 822 bylo nahrazeno RFC 2822.

zpět na obsah


Formát zpráv podle RFC 2822

Zpráva může obsahovat pouze znaky US-ASCII (znaky od 1 do 127 z ASCII). Zprávy se dělí na řádky znaků. Řádky jsou odděleny párem znaků CRLF. Zpráva se skládá z hlaviček a volitelně z těla. Tělo je odděleno od hlaviček prázdným řádkem. Řádek nesmí obsahovat více než 998 znaků a neměl by obsahovat více než 78 znaků (nepočítaje CRLF). Hlavička je složena ze jména hlavičky, které je následováno dvojtečkou, která je následována tělem hlavičky, a je ukončena CRLF. Jméno hlavičky se musí skládat z tisknutelných znaků (znaky od 33 do 126) a nesmí obsahovat dvojtečku. Tělo hlavičky může obsahovat jakékoli znaky kromě CR a LF. Může však obsahovat CRLF následováno bílým znakem. Například hlavička:

Subject: This is a test

může být reprezentována takto:

Subject: This
 is a test

V těle zprávy se mohou znaky CR a LF objevit pouze dohromady jako CRLF.

Příklad:

Return-path: <xkolaja@aurora.fi.muni.cz>
Envelope-to: xkolaja@aurora.fi.muni.cz
Delivery-date: Mon, 22 Oct 2001 21:52:58 +0200
Received: from anxur
	([147.251.48.3] helo=anxur.fi.muni.cz ident=0)
	by aurora with esmtp (Exim 3.12 #1 (Debian))
	id 15vl86-0007fz-00
	for <xkolaja@aurora.fi.muni.cz>; Mon, 22 Oct 2001 21:52:58 +0200
Received: from aragorn.ics.muni.cz (aragorn.ics.muni.cz [147.251.4.33])
	by anxur.fi.muni.cz (8.8.5/8.8.5) with ESMTP id VAA29708
	for <xkolaja@aurora.fi.muni.cz>; Mon, 22 Oct 2001 21:52:57 +0200 (MEST)
Received: from arethusa.fi.muni.cz (arethusa.fi.muni.cz [147.251.49.9])
	by aragorn.ics.muni.cz (8.8.5/8.8.5) with SMTP id VAA27662
	for <xkolaja@aurora.fi.muni.cz>; Mon, 22 Oct 2001 21:52:57 +0200 (MEST)
Received: (qmail 29253 invoked by uid 110); 22 Oct 2001 19:52:55 -0000
Delivered-To: 4063@mail.muni.cz
Received: from the incoming queue by sender:ariadna.fi.muni.cz@ariadna.fi.muni.cz at Mon, 22 Oct 2001 21:52:55 +0200
Received: (qmail 29243 invoked from network); 22 Oct 2001 19:52:52 -0000
Received: from aragorn.ics.muni.cz (147.251.4.33)
  by arethusa.fi.muni.cz with SMTP; 22 Oct 2001 19:52:52 -0000
Received: from aurora (mail@aurora.fi.muni.cz [147.251.50.200])
	by aragorn.ics.muni.cz (8.8.5/8.8.5) with ESMTP id VAA27656
	for <ace@mail.muni.cz>; Mon, 22 Oct 2001 21:52:54 +0200 (MEST)
Received: from fobos
	([147.251.50.205] helo=fobos.fi.muni.cz ident=mail)
	by aurora with esmtp (Exim 3.12 #1 (Debian))
	id 15vl82-0007fw-00
	for <ace@mail.muni.cz>; Mon, 22 Oct 2001 21:52:54 +0200
Received: from xkolaja by fobos.fi.muni.cz with local (Exim 3.32 #1 (Debian))
	id 15vl81-0000iZ-00
	for <ace@mail.muni.cz>; Mon, 22 Oct 2001 21:52:53 +0200
To: ace@mail.muni.cz
Subject: the truth
Message-Id: <E15vl81-0000iZ-00@fobos.fi.muni.cz>
From: Marcel Kolaja <xkolaja@aurora.fi.muni.cz>
Date: Mon, 22 Oct 2001 21:52:53 +0200
X-ISMU-Expires: 2002-10-22
Status: RO
Content-Length: 36
Lines: 1

"It Has To Work."       -- RFC 1925

zpět na obsah


MIME

MIME rozšiřuje formát zpráv o možnost použití jiných znaků než ASCII. Nabízí také možnost složení zprávy z několika částí.

zpět na obsah


SMTP

Design SMTP:

               +----------+                +----------+
 +--------+    |          |                |          |
 |uživatel|<-->|          |      SMTP      |          |
 +--------+    |  klient  |příkazy/odpovědi|  server  |
 +--------+    |   SMTP   |<-------------->|   SMTP   |    +------+
 |  file  |<-->|          |    a zpráva    |          |<-->| file |
 | system |    |          |                |          |    |system|
 +--------+    +----------+                +----------+    +------+

Přenášená zpráva se skládá z obálky a obsahu. Obálka musí obsahovat adresu odesílatele (na kterou by měly být směrovány chybové zprávy) a jednu nebo více adres příjemců. Obsah má dvě části: hlavičky a tělo. Klient a server jsou MTA. Příkazy SMTP jsou přenášeny po řádcích. Řádek se skládá z nula nebo více znaků a je ukončen sekvencí znaků CRLF. Klient může přenést znaky CR nebo LF pouze dohromady jako sekvenci CRLF. Relace začíná, když klient otevře spojení na server a server odpoví otevírající zprávou. Pak, když klient tuto zprávu obdrží, pošle na server příkaz EHLO (Extended HELO) indikující klientovu identitu. Použití EHLO též indikuje, že klient umí ESMTP. Starší systémy, které neumějí ESMTP by měly používat HELO místo EHLO. Server nesmí odpovědět na příkaz HELO odpovědí stylu EHLO. Pokud server na příkaz EHLO odpoví command not recognized, klient by měl být schopen poslat HELO. Pak klient pokračuje příkazem MAIL, kterým se serveru identifikuje odesílatel. Série jednoho nebo více příkazů RCPT pak podává serveru informaci o adresátech. Poté příkazem DATA začne přenos obsahu zprávy. Po odeslání obsahu zprávy musí klient serveru oznámit konec dat. Toho docílí posláním řádku obsahujícího pouze ".". Tímto řádkem také řekne klient serveru, aby poslal zprávu. Relaci klient ukončí příkazem QUIT.

Příklad (C: je klient, S: je server):

S: 220 aurora ESMTP Exim 3.12 #1 Mon, 22 Oct 2001 21:29:07 +0200
C: EHLO fobos.fi.muni.cz
S: 250-aurora Hello xkolaja at fobos [147.251.50.205]
S: 250-SIZE
S: 250-PIPELINING
S: 250 HELP
C: MAIL FROM: xkolaja@aurora.fi.muni.cz
S: 250 <xkolaja@aurora.fi.muni.cz> is syntactically correct
C: RCPT TO: ace@mail.muni.cz
S: 250 <ace@mail.muni.cz> is syntactically correct
C: DATA
S: 354 Enter message, ending with "." on a line by itself
C: (hlavicky a telo zpravy)
C: .
S: 250 OK id=15vklS-0007BV-00
C: QUIT
S: 221 aurora closing connection

zpět na obsah


Formáty mailboxu

Mailbox je schránka, do které se ukládají zprávy. Standardním UN*Xovým formátem je mbox. Zprávy jsou uloženy za sebou v jednom souboru. Začátek zprávy lze definovat regulárním výrazem "^From ". Dalším podobným formátem je MMDF folder. Zde jsou zprávy odděleny čtyřmi znaky NUL. Ve formátu MH-folder jsou zprávy uloženy v adresáři (jednotlivé zprávy jsou uloženy v souborech s číselnými názvy). Podobným formátem je Maildir. Tento formát používá Qmail.

zpět na obsah


MTA

MTA v prostředí UN*Xu:

zpět na obsah


Exim

Mnoho myšlenek a uživatelských rozhraní Exima je převzato ze Smailu 3, ale celý kód je úplně nový. Je napsán v ANSI C. Může běžet buď jako démon nebo se spouštět z inetd.

Jak Exim doručuje zprávy

Když Exim přijme zprávu zapíše dva soubory do svého spoolovacího adresáře. Ten první obsahuje informace z obálky, současný stav zprávy a hlavičky, zatímco ten druhý obsahuje tělo zprávy. Informace z obálky se skládají z adresy odesílatele a adres{y,} adresát{a,ů}. Stav zprávy obsahuje seznam adresátů, kteří už zprávu obdrželi. Jakékoli přepisování adres specifikované v konfiguraci je provedeno při přijetí zprávy. Pokud se tím nagenerují nové adresy (např. aliasingem), jsou tyto nové adresy přepsány, jakmile jsou nagenerovány. Každé zprávě je přiřazena identifikace (message id), která je dlouhá šestnáct znaků. Ta je rozdělena na tři části odělené pomlčkami. Každá část je sekvence písmen a číslic. Prvních šest znaků jsou čas přijetí zprávy (reprezentován počtem sekund). Po první pomlčce je dalších šest znaků ID procesu, který zprávu přijal. Poslední dva znaky po druhé pomlčce jsou použity pro zaručení jednoznačnosti identifikace. Jména souborů ve spoolovacím adresáři se skládají z identifikace zprávy následované -H pro soubor obsahující obálku a hlavičky a -D pro datový soubor. Implicitně jsou tyto soubory umístěny v adresáři input nacházejícím se v hlavním spoolovacím adresáři Exima. Zpráva zůstává ve spoolovacím adresáři dokud není kompletně doručena všem adresátům nebo na chybovou adresu nebo dokud není smazána administrátorem nebo uživatelem, který ji původně vytvořil. V případě, že doručování nemůže dále pokračovat, např. když zpráva nemůže být ani doručena adresátům ani vrácena odesílateli, je označena jako zmrazená (frozen) ve frontě a nejsou žádné další pokusy o doručení. Administrátor může takové zprávy rozmrazit, pokud byl problém odstraněn a také zmrazit některé zprávy ručně, pokud je to nutné. Pokud je nastavena volba auto_thaw Exim se po určitém čase pokusí zprávy znovu doručit. Poté, co proběhne doručení zprávy, zapíše Exim informaci o doručení do logu.

Instalace a konfigurace

V následujících krocích si ve stručnosti popíšeme instalaci a konfiguraci na systému Debian GNU/Linux 2.2 potato. V této distribuci je použit Exim verze 3.12-10.1. Nainstalujeme ho tradičně příkazem apt-get install exim. Exim nepoužívá debconf, takže se po stažení a rozbalení balíčku spustí jeho vlastní konfigurační nástroj, který nese jméno eximconfig. Ten nám nabídne pět předdefinovaných konfigurací (Internet site, Internet site using smarthost, Satellite system, Local delivery only, No configuration). Podle zvolené možnosti se nás zeptá na několik otázek a Exim je zkonfigurován. Pokud nám toto nestačí, upravíme si konfigurační soubor /etc/exim.conf ručně. Debian startuje implicitně Exima z inetd. Pokud chceme, aby nám běžel Exim jako démon, stačí zakomentovat řádek začínající smtp/etc/inetd.conf a démona nastartovat (/etc/init.d/exim start).

Příklad konfiguračního souboru:

# This is the main exim configuration file.
# It was originally generated by `eximconfig', part of the exim package
# distributed with Debian, but it may edited by the mail system administrator.
# This file originally generated by eximconfig at Wed Oct  3 13:38:54 CEST 2001
# See exim info section for details of the things that can be configured here.

# Please see the manual for a complete list
# of all the runtime configuration options that can be included in a
# configuration file.

# This file is divided into several parts, all but the last of which are
# terminated by a line containing the word "end". The parts must appear
# in the correct order, and all must be present (even if some of them are
# in fact empty). Blank lines, and lines starting with # are ignored.

######################################################################
#                    MAIN CONFIGURATION SETTINGS                     #
######################################################################

# Specify the domain you want to be added to all unqualified addresses
# here. Unqualified addresses are accepted only from local callers by
# default. See the receiver_unqualified_{hosts,nets} options if you want
# to permit unqualified addresses from remote sources. If this option is
# not set, the primary_hostname value is used for qualification.

qualify_domain = foo.cz

# If you want unqualified recipient addresses to be qualified with a different
# domain to unqualified sender addresses, specify the recipient domain here.
# If this option is not set, the qualify_domain value is used.

# qualify_recipient =

# Specify your local domains as a colon-separated list here. If this option
# is not set (i.e. not mentioned in the configuration file), the
# qualify_recipient value is used as the only local domain. If you do not want
# to do any local deliveries, uncomment the following line, but do not supply
# any data for it. This sets local_domains to an empty string, which is not
# the same as not mentioning it at all. An empty string specifies that there
# are no local domains; not setting it at all causes the default value (the
# setting of qualify_recipient) to be used.

local_domains = foo.cz:localhost

# Allow mail addressed to our hostname, or to our IP address.

local_domains_include_host = true
local_domains_include_host_literals = true

# Domains we relay for; that is domains that aren't considered local but we 
# accept mail for them.

#relay_domains = 

# If this is uncommented, we accept and relay mail for all domains we are 
# in the DNS as an MX for.

relay_domains_include_local_mx = true

# No local deliveries will ever be run under the uids of these users (a colon-
# separated list). An attempt to do so gets changed so that it runs under the
# uid of "nobody" instead. This is a paranoic safety catch. Note the default
# setting means you cannot deliver mail addressed to root as if it were a
# normal user. This isn't usually a problem, as most sites have an alias for
# root that redirects such mail to a human administrator.

# However, you chose not to have such an alias, so this is commented out

never_users = root

# The setting below causes Exim to do a reverse DNS lookup on all incoming
# IP calls, in order to get the true host name. If you feel this is too
# expensive, you can specify the networks for which a lookup is done, or
# remove the setting entirely.

host_lookup = *

# The setting below would, if uncommented, cause Exim to check the syntax of
# all the headers that are supposed to contain email addresses (To:, From:,
# etc). This reduces the level of bounced bounces considerably.

headers_check_syntax

# Exim contains support for the Realtime Blocking List (RBL) that is being
# maintained as part of the DNS. See http://maps.vix.com/rbl/ for
# background. Uncommenting the following line will make Exim reject mail
# from any host whose IP address is blacklisted in the RBL at maps.vix.com.

rbl_domains = rbl.maps.vix.com
#rbl_reject_recipients = false
rbl_warn_header = true

# The setting below allows your host to be used as a mail relay only by
# localhost: it locks out the use of your host as a mail relay by any
# other host. See the section of the manual entitled "Control of relaying" 
# for more info.

host_accept_relay = localhost

# If you want Exim to support the "percent hack" for all your local domains,
# uncomment the following line. This is the feature by which mail addressed
# to x%y@z (where z is one of your local domains) is locally rerouted to
# x@y and sent on. Otherwise x%y is treated as an ordinary local part

# percent_hack_domains=*

# If this option is set, then any process that is running as one of the
# listed users may pass a message to Exim and specify the sender's
# address using the "-f" command line option, without Exim's adding a
# "Sender" header.

trusted_users = mail

# If this option is true, the SMTP command VRFY is supported on incoming
# SMTP connections; otherwise it is not.

smtp_verify = false

# Some operating systems use the "gecos" field in the system password file
# to hold other information in addition to users' real names. Exim looks up
# this field when it is creating "sender" and "from" headers. If these options
# are set, exim uses "gecos_pattern" to parse the gecos field, and then
# expands "gecos_name" as the user's name. $1 etc refer to sub-fields matched
# by the pattern.

gecos_pattern = ^([^,:]*)
gecos_name = $1

# This sets the maximum number of messages that will be accepted in one
# connection. The default is 10, which is probably enough for most purposes,
# but is too low on dialup SMTP systems, which often have many more mails
# queued for them when they connect.

smtp_accept_queue_per_connection = 100

# Send a mail to the postmaster when a message is frozen. There are many
# reasons this could happen; one is if exim cannot deliver a mail with no
# return address (normally a bounce) another that may be common on dialup
# systems is if a DNS lookup of a smarthost fails. Read the documentation
# for more details: you might like to look at the auto_thaw option

freeze_tell_mailmaster = true

# This string defines the contents of the \`Received' message header that
# is added to each message, except for the timestamp, which is automatically
# added on at the end, preceded by a semicolon. The string is expanded each
# time it is used.

received_header_text = "Received: \
         ${if def:sender_rcvhost {from ${sender_rcvhost}\n\t}\
         {${if def:sender_ident {from ${sender_ident} }}\
         ${if def:sender_helo_name {(helo=${sender_helo_name})\n\t}}}}\
         by ${primary_hostname} \
         ${if def:received_protocol {with ${received_protocol}}} \
         (Exim ${version_number} #${compile_number} (Debian))\n\t\
         id ${message_id}\
         ${if def:received_for {\n\tfor <$received_for>}}"
end


######################################################################
#                      TRANSPORTS CONFIGURATION                      #
######################################################################
#                       ORDER DOES NOT MATTER                        #
#     Only one appropriate transport is called for each delivery.    #
######################################################################

# This transport is used for local delivery to user mailboxes. On debian
# systems group mail is used so we can write to the /var/spool/mail
# directory. (The alternative, which most other unixes use, is to deliver
# as the user's own group, into a sticky-bitted directory)

local_delivery:
  driver = appendfile
  group = mail
  mode = 0660
  mode_fail_narrower = false
  envelope_to_add = true
  file = /var/spool/mail/${local_part}

# This transport is used for handling pipe addresses generated by
# alias or .forward files. If the pipe generates any standard output,
# it is returned to the sender of the message as a delivery error. Set
# return_fail_output instead if you want this to happen only when the
# pipe fails to complete normally.

address_pipe:
  driver = pipe
  return_output

# This transport is used for handling file addresses generated by alias
# or .forward files.

address_file:
  driver = appendfile

# This transport is used for handling file addresses generated by alias
# or .forward files if the path ends in "/", which causes it to be treated
# as a directory name rather than a file name. Each message is then delivered
# to a unique file in the directory. If instead you want all such deliveries to
# be in the "maildir" format that is used by some other mail software,
# uncomment the final option below. If this is done, the directory specified
# in the .forward or alias file is the base maildir directory.
#
# Should you want to be able to specify either maildir or non-maildir
# directory-style deliveries, then you must set up yet another transport,
# called address_directory2. This is used if the path ends in "//" so should
# be the one used for maildir, as the double slash suggests another level
# of directory. In the absence of address_directory2, paths ending in //
# are passed to address_directory.

address_directory:
  driver = appendfile
  no_from_hack
  prefix = ""
  suffix = ""
# maildir_format

# This transport is used for handling autoreplies generated by the filtering
# option of the forwardfile director.

address_reply:
  driver = autoreply

# This transport is used for procmail

procmail_pipe:
  driver = pipe
  command = "/usr/bin/procmail -d ${local_part}"
  return_path_add
  delivery_date_add
  envelope_to_add
  check_string = "From "
  escape_string = ">From "
  user = $local_part
  group = mail

# This transport is used for delivering messages over SMTP connections.

remote_smtp:
  driver = smtp

end


######################################################################
#                      DIRECTORS CONFIGURATION                       #
#             Specifies how local addresses are handled              #
######################################################################
#                          ORDER DOES MATTER                         #
#   A local address is passed to each in turn until it is accepted.  #
######################################################################

# This allows local delivery to be forced, avoiding alias files and
# forwarding.

real_local:
  prefix = real-
  driver = localuser
  transport = local_delivery

# This director handles aliasing using a traditional /etc/aliases file.
# If any of your aliases expand to pipes or files, you will need to set
# up a user and a group for these deliveries to run under. You can do
# this by uncommenting the "user" option below (changing the user name
# as appropriate) and adding a "group" option if necessary.

system_aliases:
  driver = aliasfile
  file_transport = address_file
  pipe_transport = address_pipe
  file = /etc/aliases
  search_type = lsearch
# user = list
# Uncomment the above line if you are running smartlist


# This director runs procmail for users who have a .procmailrc file

procmail:
  driver = localuser
  transport = procmail_pipe
  require_files = ${local_part}:+${home}:+${home}/.procmailrc:+/usr/bin/procmail
  no_verify
    
# This director handles forwarding using traditional .forward files.
# It also allows mail filtering when a forward file starts with the 
# string "# Exim filter": to disable filtering, uncomment the "filter" 
# option. The check_ancestor option means that if the forward file 
# generates an address that is an ancestor of the current one, the 
# current one gets passed on instead. This covers the case where A is 
# aliased to B and B has a .forward file pointing to A.

# For standard debian setup of one group per user, it is acceptable---normal
# even---for .forward to be group writable. If you have everyone in one
# group, you should comment out the "modemask" line. Without it, the exim
# default of 022 will apply, which is probably what you want.

userforward:
  driver = forwardfile
  file_transport = address_file
  pipe_transport = address_pipe
  reply_transport = address_reply
  no_verify
  check_ancestor
  file = .forward
  modemask = 002
  filter

# This director matches local user mailboxes.

localuser:
  driver = localuser
  transport = local_delivery

end


######################################################################
#                      ROUTERS CONFIGURATION                         #
#            Specifies how remote addresses are handled              #
######################################################################
#                          ORDER DOES MATTER                         #
#  A remote address is passed to each in turn until it is accepted.  #
######################################################################

# Remote addresses are those with a domain that does not match any item
# in the "local_domains" setting above.

# This router routes to remote hosts over SMTP using a DNS lookup with
# default options.

lookuphost:
  driver = lookuphost
  transport = remote_smtp

# This router routes to remote hosts over SMTP by explicit IP address,
# given as a "domain literal" in the form [nnn.nnn.nnn.nnn]. The RFCs
# require this facility, which is why it is enabled by default in Exim.
# If you want to lock it out, set forbid_domain_literals in the main
# configuration section above.

literal:
  driver = ipliteral
  transport = remote_smtp

end


######################################################################
#                      RETRY CONFIGURATION                           #
######################################################################

# This single retry rule applies to all domains and all errors. It specifies
# retries every 15 minutes for 2 hours, then increasing retry intervals,
# starting at 2 hours and increasing each time by a factor of 1.5, up to 16
# hours, then retries every 8 hours until 4 days have passed since the first
# failed delivery.

# Domain               Error       Retries
# ------               -----       -------

*                      *           F,2h,15m; G,16h,2h,1.5; F,4d,8h

end


######################################################################
#                      REWRITE CONFIGURATION                         #
######################################################################


# There are no rewriting specifications in this default configuration file.

*@bar.cz	$1@baz.cz	t

# End of Exim configuration file

zpět na obsah


Odkazy

zpět na obsah


Valid HTML 4.0!