head	1.6;
access;
symbols
	tcllib-1-7:1.4
	tcllib-1-6-1:1.3.2.1
	tcllib-1-6-branch:1.3.0.2
	tcllib-1-6:1.3
	tcllib-1-4-0:1.3;
locks; strict;
comment	@# @;


1.6
date	2005.09.01.12.54.17;	author patthoyts;	state dead;
branches;
next	1.5;

1.5
date	2005.02.13.08.59.25;	author patthoyts;	state Exp;
branches;
next	1.4;

1.4
date	2004.03.09.08.20.18;	author andreas_kupries;	state Exp;
branches;
next	1.3;

1.3
date	2003.01.03.00.58.08;	author patthoyts;	state Exp;
branches
	1.3.2.1;
next	1.2;

1.2
date	2002.12.27.00.21.39;	author patthoyts;	state Exp;
branches;
next	1.1;

1.1
date	2002.10.08.20.23.29;	author patthoyts;	state Exp;
branches;
next	;

1.3.2.1
date	2004.05.24.02.58.09;	author andreas_kupries;	state Exp;
branches;
next	;


desc
@@


1.6
log
@Rationalized to a single Tk demo
@
text
@#! /bin/sh
# -*- tcl -*- \
exec tclsh "$0" ${1+"$@@"}

# tk_smtpdMIME -Copyright (C) 2002 Pat Thoyts <patthoyts@@users.sourceforge.net>
#
# Simple test of the mail server. All incoming messages are displayed in a 
# message dialog.
#
# This uses the new MIME token passing interface to the smtpd module.
#
# This example works nicely under Windows or within tkcon.
#
# Usage tk_smtpd 0.0.0.0 8025
#    or tk_smtpd 127.0.0.1 2525
#    or tk_smtpd
# to listen to the default port 25 on all tcp/ip interfaces.
#
# -------------------------------------------------------------------------
# This software 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 file 'license.terms' for
# more details.
# -------------------------------------------------------------------------

package require Tcl 8.3
package require Tk
package require smtpd
package require mime

#wm withdraw .
wm title . "Tcllib SMTPD sample."
set _dlgid 0

# Handle new mail by raising a message dialog for each recipient.
proc deliverMIME {token} {

    set senders [mime::getheader $token From]
    set recipients [mime::getheader $token To]

    if {[catch {eval array set saddr \
                    [mime::parseaddress [lindex $senders 0]]}]} {
        error "invalid sender address \"$senders\""
    }
    set mail "From $saddr(address) [clock format [clock seconds]]\n"
    append mail [mime::buildmessage $token]
    foreach rcpt $recipients {
        if {! [catch {eval array set addr [mime::parseaddress $rcpt]}]} {
            display "To: $addr(address)" $mail
        }
    }
}

proc display {title mail} {
    global _dlgid
    incr _dlgid
    set dlg [toplevel .dlg$_dlgid]
    set frm [frame ${dlg}.f -bd 0]
    set txt [text ${frm}.e -yscrollcommand [list ${frm}.sb set]]
    set scr [scrollbar ${frm}.sb -command [list $txt yview]]
    set but [button ${dlg}.b -text "Dismiss" -command [list destroy $dlg]]
    pack $scr -side right -fill y
    pack $txt -side left -fill both -expand 1
    pack $frm -side top -fill both -expand 1
    pack $but -side bottom
    wm title $dlg $title
    $txt insert 0.0 [string map {\r\n \n} $mail]
}

# Accept everyone except those spammers on 192.168.1.* :)
proc validate_host {ipnum} {
    if {[string match "192.168.1.*" $ipnum]} {
        error "your domain is not allowed to post, Spammers!"
    }
}

# Accept mail from anyone except user 'denied'
proc validate_sender {address} {
    eval array set addr [mime::parseaddress $address]
    if {[string match "denied" $addr(local)]} {
        error "mailbox $addr(local) denied"
    }
    return    
}

# Only reject mail for recipients beginning with 'bogus'
proc validate_recipient {address} {
    eval array set addr [mime::parseaddress $address]
    if {[string match "bogus*" $addr(local)]} {
        error "mailbox $addr(local) denied"
    }
    return
}

# Setup the mail server
smtpd::configure \
    -deliverMIME        ::deliverMIME \
    -validate_host      ::validate_host \
    -validate_recipient ::validate_recipient \
    -validate_sender    ::validate_sender

# Run the server on the default port 25. For unix change to 
# a high numbered port eg: 2525 or 8025 etc with
# smtpd::start 127.0.0.1 8025 or smtpd::start 0.0.0.0 2525

set iface 0.0.0.0
set port 25

if {$tcl_interactive } {

    puts {you'll want to issue 'smtpd::start' to begin}

} else {

    if {$argc > 0} {
        set iface [lindex $argv 0]
    }
    if {$argc > 1} {
        set port [lindex $argv 1]
    }
        
    set b1 [button .b -text "Stop Mail server" \
                -command [list ::smtpd::stop]]
    set b2 [button .b -text "Start Mail server" \
                -command [list ::smtpd::start $iface $port]]
    pack -side top $b1 $b2
    smtpd::start $iface $port
}

#
# Local variables:
#  mode: tcl
#  indent-tabs-mode: nil
# End:
@


1.5
log
@Added start/stop buttons to the main window.
@
text
@@


1.4
log
@Unified the startup header of all applications, using
suggestions made by Stuart Cassof <stwo@@telus.net>.
@
text
@d30 3
a32 1
wm withdraw .
d67 1
a67 1
    $txt insert 0.0 $mail
d122 5
@


1.3
log
@Fix handling of RFC822 addresses.
@
text
@d2 3
a4 1
#
a24 2
# \
exec wish "$0" ${1+"$@@"}
d26 2
a29 1
package require Tk
@


1.3.2.1
log
@Downgraded to version 1.3.6, removed -decode extension from
this branch.

Import of ftpd bugfix by Gerald Lester.

Last commit was a bad update, caused duplicates of changes
to appear. Failed testsuite. Removed all the duplicates now.

Fixed SF Tcllib Bug 954328. Mime now adapts at runtime to
whatever version of md5 has been loaded.

Updated test for rewritten adjust which fixed the infinite
looping demonstrated by tests 2.6 and 2.7. Also fixed a var
usage typo which caused a copy of the input to appear in the
output, before the expected formatted result.

Fixed bug in the processing of multi-word section titles for
text based formats.

Fixed bug 951568, regarding the usage of Trf's generic
transform.

Fixed problems with jpeg recognition (was unable to detect a
jpeg file, if it contained exif data).

Changelog for last patch, and updates in related package.

Completed application of code for various fixes.

Rewritten text adjustment and hyphenation, fixing SF TCllib
Bug 882402.

Fixed SF Tcllib Bug 936064, and evals more robust.

Fixed SF Tcllib Bug 893516

Fixed SF Tcllib Patch 763712

Fixed SF Tcllib Patch 758742

Fixed SF Tcllib Bug 620852

Eval usage made more robust and similar.

Fixed SF Tcllib Bug 943146.

Fixed SF Tcllib Bug 940651

SF Tcllib Bug 784519 fixed.

Pat: sak.tcl update for better use of critcl.

Joe: Fix in doctools xml support.

Import bugfix by Pat Thoyts, Handling of data starting with
hyphen/dash

Import of uuencode changes by Jeff Hobbs.

Changed defaults for package 'log'. No output for the all
levels below 'error'.

Unified the startup header of all applications, using
suggestions made by Stuart Cassof <stwo@@telus.net>.

Added testcase for Tcllib SF Bug 860753. The bug itself was
already fixed for Tcllib 1.6.

Fix for bug 899204. Test data file is opened read-only, and
tests made independent of each other.

Bugfix 899152, 899209. Require Tcl 8.2 for installer, delete
file before writing over it.

Import of time fix by Pat Thoyts, patch #905132.

Cleanup fix: Snit depends on Tcl 8.4, this is documented,
however neither package index, nor testsuite enforced the
restriction, allowing for errors. This has been changed now.

Fixed typos
@
text
@d2 1
a2 3
# -*- tcl -*- \
exec tclsh "$0" ${1+"$@@"}

d23 2
a25 2
package require Tcl 8.3
package require Tk
d28 1
@


1.2
log
@Change from using tk_messageBox to a proper dialog to avoid blocking
@
text
@d35 2
a36 2
    set sender [lindex [mime::getheader $token From] 0]
    set recipients [lindex [mime::getheader $token To] 0]
d38 3
a40 2
    if {[catch {eval array set saddr [mime::parseaddress $sender]}]} {
        error "invalid sender address \"$sender\""
a43 1

@


1.1
log
@Implemented feature request #531531 to provide MIME tokens to the backend.
@
text
@d30 1
d46 1
a46 1
            tk_messageBox -title "To: $addr(address)" -message $mail
d49 16
@

