Tetra-WebBBS Debugger 6.10

Contents of /home/zoetecnocampoco/public_html/cgi-bin/bbs/lib/webbbs_post.pl

    1- #<<<
    2- #######################################
    3- #    ---  Tetra-WebBBS  --- 
    4- # By:             tetrabb.com
    5- # Version:        6.10
    6- # Last modified:  2009-11-01
    7- # Copyright (c)   2006-2009
    8- # Website:        http://tetrabb.com
    9- # For more details see license.txt
   10- #
   11- # Core script:    webbbs_post.pl
   12- # Authors:        Rainer Libowski
   13- #                 Tarty
   14- # Derived from code by Darryl Burgdorf
   15- #######################################
   16- #>>>
   17- 
   18- sub WebBBS {
   19- &Parse_Post;
   20- my $filename = $FORM{'name'};
   21- $filename =~ s/[^\w\.\-\']/\+/g;
   22- $filename =~ tr/A-Z/a-z/;
   23- $filename = $UserProfileDir . '/' . $filename . '.txt';
   24- if ( -s $filename ) {
   25- my $pw_ok = $read5x->check_profile_password( 'username' => $FORM{'name'},
   26-                                              'password' => $FORM{'password'},
   27-                                              'file'     => $filename,
   28- );
   29- if ( !$pw_ok ) {
   30- print "Content-type: text/html\n\n";
   31- &Error( '9122', '9123' );
   32- exit;
   33- }
   34- }
   35- &Initialize_Data;
   36- unless ($shortboardname) { $shortboardname = $boardname; }
   37- &MessageDBM_close();
   38- &LockOpen( DBLOCK, "$dir/messagelist.lock" );
   39- &MessageDBMWrite;
   40- &PostMessage;
   41- } ## end sub WebBBS
   42- 
   43- sub Parse_Post {
   44- if ( $ENV{'REQUEST_METHOD'} =~ /get/i ) {
   45- exit;
   46- }
   47- %FORM = %{$post};
   48- delete $FORM{'postgraphic'};
   49- $FORM{'body'} = "\n" . $FORM{'body'};
   50- 
   51- my $is_registered = 0;
   52- if ( lc( $FORM{'name'} ) ne lc( $tbb->{'session'}->{'board_user'}->{'name'} ) ) {
   53- my $verified_ref = $tbb->{'db'}->verify_exists_data( 'type' => 'profile',
   54-                                                      'id'   => $FORM{'name'}, );
   55- if ($verified_ref) {
   56- $is_registered = 1;
   57- }
   58- }
   59- else {
   60- $is_registered = $tbb->{'session'}->{'board_user'}->{'is_registered'};
   61- }
   62- 
   63- if ($PRO::VERSION) {
   64- &PRO::cb_message_parse_1( 'tbb'      => $main::tbb,
   65-                           'FORM_ref' => \%FORM, );
   66- }
   67- 
   68- @naughtywords = ();
   69- if (    ( !$AdminRun )
   70-      && $NaughtyWordsFile
   71-      && ( !( ( $is_registered && ( $BypassContentFilter == 2 ) ) || ( $BypassContentFilter == 1 ) ) ) )
   72- {
   73- open( NAUGHTY, "$NaughtyWordsFile" );
   74- @naughtywords = <NAUGHTY>;
   75- chomp(@naughtywords);
   76- close(NAUGHTY);
   77- }
   78- 
   79- $RogueSpace = chr(160);
   80- my $naughty_cnt = 0;
   81- if ($SpamScore) {
   82- $SpamScore = int($SpamScore);
   83- }
   84- foreach $entry ( keys %FORM ) {
   85- @pres = ();
   86- $FORM{$entry} =~ s/$RogueSpace/ /g;
   87- if ( $entry eq "body" ) {
   88- $bodytest = 0;
   89- @bodytext = split( /\n/, $FORM{$entry} );
   90- foreach $bodyline (@bodytext) {
   91- next if length($bodyline) < 2;
   92- next
   93-     unless (    ( $bodyline !~ /^$AutoQuoteChar/i )
   94-              || ( length($bodyline) > ( $InputColumns + 1 ) ) );
   95- $bodytest = 1;
   96- last;
   97- }
   98- unless ($bodytest) { $FORM{$entry} = ""; }
   99- }
  100- 
  101- if (@naughtywords) {
  102- unless (    ( $entry eq "password" )
  103-          || ( $entry eq "url" )
  104-          || ( $entry eq "imageurl" ) )
  105- {
  106- if ( $CensorPosts == 1 ) {
  107- foreach $naughtyword (@naughtywords) {
  108- next if ( length($naughtyword) < 2 );
  109- $FORM{$entry} =~ s/$naughtyword/#####/ig;
  110- }
  111- }
  112- elsif ( $CensorPosts == 2 ) {
  113- foreach $naughtyword (@naughtywords) {
  114- next if ( length($naughtyword) < 2 );
  115- 
  116- my $this_naughty_cnt = () = $FORM{$entry} =~ /$naughtyword/ig;
  117- if ($this_naughty_cnt) {
  118- $naughty_cnt += $this_naughty_cnt;
  119- if ( $SpamScore && ( $naughty_cnt >= $SpamScore ) ) {
  120- $tbb->send_error_plain( "1600", "1601", '1700' );
  121- exit;
  122- }
  123- $Moderated      = 1;
  124- $email_list     = 1;
  125- $NaughtyModFlag = 1;
  126- }
  127- }
  128- }
  129- else {
  130- foreach $naughtyword (@naughtywords) {
  131- next if ( length($naughtyword) < 2 );
  132- if ( $FORM{$entry} =~ /$naughtyword/i ) {
  133- $NaughtyFlag = 1;
  134- last;
  135- }
  136- }
  137- }
  138- }
  139- }
  140- unless ( $entry eq "subjectprefix" ) {
  141- unless ( ( $AllowHTML > 1 ) && ( $entry eq "body" ) ) {
  142- if ( !$AdminRun ) {
  143- $FORM{$entry} =~ s/<!--([^>]|\n)*-->/ /g;
  144- }
  145- }
  146- if ( ( $AllowHTML < 1 ) || ( $entry ne "body" ) ) {
  147- $FORM{$entry} =~ s/<([^>]|\n)*(>|$)/ /g;
  148- }
  149- $HTMLConvert = 0;
  150- unless ( ( $AllowHTML eq "1" ) && ( $entry eq "body" ) ) {
  151- $FORM{$entry} =~ s/\&/\&\;/g;
  152- $FORM{$entry} =~ s/"/\"\;/g;
  153- $FORM{$entry} =~ s/</\<\;/g;
  154- $FORM{$entry} =~ s/>/\>\;/g;
  155- $HTMLConvert = 1;
  156- }
  157- if ( $entry eq "body" ) {
  158- $BodyPreview = $FORM{$entry};
  159- $FORM{$entry} =~ s/\n/ <BR>/g;
  160- $FORM{$entry} = "$FORM{$entry}";
  161- if ( $AutoHotlink && !( $FORM{'EditPost'} ) ) {
  162- unless ( $AllowHTML eq "2" ) {
  163- $FORM{$entry} =~ s/\&\;/\&/g;
  164- $FORM{$entry} =~ s/\"\;/"/g;
  165- $FORM{$entry} =~ s/\<\;/</g;
  166- $FORM{$entry} =~ s/\>\;/>/g;
  167- $HTMLConvert = 0;
  168- }
  169- }
  170- if ($AutoHotlink) {
  171- 
  172- $AHL_target = '_blank' unless $AHL_target;
  173- 
  174- $FORM{$entry} =~ s/([ <>])([\w]+:\/\/[\w\*\+\'\!\(\)-?&;,#~=\.\/\$\%\@]+[\w\/])/$1<a href="$2" target="$AHL_target">$2<\/A>/g;
  175- $FORM{$entry} =~ s/([ <>])(www\.[\w\*\+\'\!\(\)-?&;,#~=\.\/\$\%\@]+[\w\/])/$1<a href="http:\/\/$2" target="$AHL_target">$2<\/A>/g;
  176- $FORM{$entry} =~ s/([ <>])([^\s"<>]+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,3})(\]?))/$1<a href="mailto:$2">$2<\/A>/g;
  177- }
  178- if (%SmileyCode) {
  179- foreach $key ( keys %SmileyCode ) {
  180- $key2 = $key;
  181- $key2 =~ s/([\[\]\(\)\\\*\+\?\\\|])/\\$1/g;
  182- if ($HTMLConvert) {
  183- $key2 =~ s/\&/\&\;/g;
  184- $key2 =~ s/"/\"\;/g;
  185- $key2 =~ s/</\<\;/g;
  186- $key2 =~ s/>/\>\;/g;
  187- }
  188- $FORM{$entry} =~ s/([ <>])($key2)/$1$SmileyCode{$key}/g;
  189- }
  190- }
  191- if (%FormatCode) {
  192- foreach $key ( keys %FormatCode ) {
  193- $key2 = $key;
  194- $key2 =~ s/([\[\]\(\)\\\*\+\?\\\|])/\\$1/g;
  195- if ($HTMLConvert) {
  196- $key2 =~ s/\&/\&\;/g;
  197- $key2 =~ s/"/\"\;/g;
  198- $key2 =~ s/</\<\;/g;
  199- $key2 =~ s/>/\>\;/g;
  200- }
  201- $FORM{$entry} =~ s/$key2/$FormatCode{$key}/ig;
  202- }
  203- }
  204- $FORM{$entry} =~ s/\s*<br(\s*\/)?>/<BR>/ig;
  205- 
  206- @pres = ();
  207- while ( $FORM{$entry} =~ m/<pre>(.+?)<\/pre>/ig ) {
  208- push( @pres, $1 );
  209- }
  210- for (@pres) {
  211- my $code    = $_;
  212- my $newcode = $code;
  213- $newcode =~ s/\s*<br(\s*\/)?>/<FeEd>/ig;
  214- $newcode =~ s/ /<BlAnK>/ig;
  215- $_ = $newcode;
  216- $FORM{$entry} =~ s/\Q$code\E/$newcode/g;
  217- }
  218- $FORM{$entry} =~ s/<BR>\t/<BR><BR>/g;
  219- $FORM{$entry} =~ s/\s+/ /g;
  220- $FORM{$entry} =~ s/<BR>\s/<BR>/g;
  221- $FORM{$entry} =~ s/\s<BR>/<BR>/g;
  222- $FORM{$entry} =~ s/<BR><BR>/<P>/g;
  223- $FORM{$entry} =~ s/<P><BR>/<P>/g;
  224- if ( ( !$SingleLineBreaks ) && ( !( $AllowHTML eq "1" ) ) ) {
  225- $FORM{$entry} =~ s/<BR>$AutoQuoteChar/<BRR>/g;
  226- $FORM{$entry} =~ s/<BR>>/<BRR>/g;
  227- $FORM{$entry} =~ s/<BR>>/<BRR>/g;
  228- $FORM{$entry} =~ s/<BR>/ /g;
  229- $FORM{$entry} =~ s/<BRR>/<BR>$AutoQuoteChar/g;
  230- }
  231- 
  232- $FORM{$entry} =~ s/<P>\s*<BR>/<P>/ig;
  233- 
  234- $FORM{$entry} =~ s/\s+/ /g;
  235- $FORM{$entry} =~ s/^\s+//g;
  236- $FORM{$entry} =~ s/\s+$//g;
  237- $FORM{$entry} =~ s/<P>/\n<P>/ig;
  238- $FORM{$entry} =~ s/<BR>/\n<BR>/ig;
  239- $FORM{$entry} =~ s/<P>\n//ig;
  240- $FORM{$entry} =~ s/<BR>\n//ig;
  241- 
  242- $FORM{$entry} =~ s/<BR>(<\/?t[ahbrd])/$1/ig;
  243- $FORM{$entry} =~ s/<(P|BR)>(<\/?(ol|ul|dl|li|dd))/$2/ig;
  244- $FORM{$entry} =~ s/<(P|BR)>(<\/?h\d)/$2/ig;
  245- $FORM{$entry} =~ s/<(P|BR)>(<\/?div)/$2/ig;
  246- 
  247- for (@pres) {
  248- my $code    = $_;
  249- my $newcode = $code;
  250- $newcode      =~ s/<FeEd>/\n/g;
  251- $newcode      =~ s/<BlAnK>/ /g;
  252- $FORM{$entry} =~ s/\Q$code\E/$newcode/g;
  253- }
  254- 
  255- $FORM{$entry} =~ s/<(BR|P)><PRE>/<PRE>/gi;
  256- $FORM{$entry} =~ s/\n*<PRE>\n*/\n<PRE>/sgi;
  257- $FORM{$entry} =~ s/\n*<\/PRE>\n*/<\/PRE>\n/sgi;
  258- 
  259- $FORM{$entry} =~ s/^\n+//g;
  260- $FORM{$entry} =~ s/^<BR>/<P>/sig;
  261- 
  262- } else {
  263- $FORM{$entry} =~ s/\n/ /g;
  264- }
  265- }
  266- }
  267- undef @naughtywords;
  268- $FORM{'PostGraphic'} = $post->{'postgraphic'}->{'content'};
  269- if (    ( $post->{'postgraphic'}->{'filename'} =~ /\.jpg$/i )
  270-      || ( $post->{'postgraphic'}->{'filename'} =~ /\.jpeg$/i ) )
  271- {
  272- $PicType = "JPG";
  273- }
  274- elsif ( $post->{'postgraphic'}->{'filename'} =~ /\.gif$/i ) {
  275- $PicType = "GIF";
  276- }
  277- elsif ( $post->{'postgraphic'}->{'filename'} =~ /\.png$/i ) {
  278- $PicType = "PNG";
  279- }
  280- if ($PRO::VERSION) {
  281- &PRO::cb_message_parse_3( 'tbb'      => $main::tbb,
  282-                           'FORM_ref' => \%FORM, );
  283- }
  284- } ## end sub Parse_Post
  285- 
  286- sub PostMessage {
  287- $FORM{'followup'} =~ s/\D//g;
  288- $FORM{'editmsg'}  =~ s/\D//g;
  289- if (    $ArchiveOnly
  290-      || ( $FORM{'followup'}      && !($AllowResponses) )
  291-      || ( !( $FORM{'followup'} ) && !($AllowNewThreads) ) )
  292- {
  293- &Error( "9520", "9521" );
  294- }
  295- if ( $RequireEmail && ( !$email ) ) {
  296- &Error( "9210", "9211" );
  297- }
  298- if ( $FORM{'wantnotice'} && $email ) {
  299- my $email_is_banned = $tbb->{'db'}->verify_filters( 'type'     => 'bannedEmails',
  300-                                                     'to_check' => $email, );
  301- if ($email_is_banned) {
  302- delete $FORM{'wantnotice'};
  303- }
  304- }
  305- 
  306- if ( $FORM{'followup'} ) {
  307- unless ( $MessageList{ $FORM{'followup'} } > 0 ) {
  308- &Error( "9220", "9221" );
  309- }
  310- }
  311- my $check_imaurl = $FORM{'imageurl'};
  312- $check_imaurl =~ s/^(http)?:?(\/)*//gi;
  313- $check_imaurl =~ s/\s+//g;
  314- if (    ($check_imaurl)
  315-      && ( $check_imaurl !~ /\.(gif|jpg|jpeg|png)$/i ) )
  316- {
  317- &Error( "9656", "9657" );
  318- exit;
  319- }
  320- if ($ResolveIPs) {
  321- if ( ( $ENV{'REMOTE_ADDR'} =~ /^\d+\.\d+\.\d+\.\d+$/ )
  322-      && ( !( $ENV{'REMOTE_HOST'} )
  323-           || ( $ENV{'REMOTE_HOST'} =~ /^\d+\.\d+\.\d+\.\d+$/ ) )
  324-     )
  325- {
  326- @domainbytes = split( /\./, $ENV{'REMOTE_ADDR'} );
  327- $packaddr = pack( "C4", @domainbytes );
  328- $resolvedip = ( gethostbyaddr( $packaddr, 2 ) )[0];
  329- unless ( $resolvedip =~ /^[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,3})$/ ) {
  330- $resolvedip = "";
  331- }
  332- if ($resolvedip) {
  333- $ENV{'REMOTE_HOST'} = $resolvedip;
  334- }
  335- }
  336- }
  337- unless ( $ENV{'REMOTE_HOST'} ) {
  338- $ENV{'REMOTE_HOST'} = $ENV{'REMOTE_ADDR'};
  339- }
  340- $profilename = $name;
  341- $profilename =~ s/[^\w\.\-\']/\+/g;
  342- $profilename =~ tr/A-Z/a-z/;
  343- if ($RequireProfile) {
  344- unless ( -e "$UserProfileDir/$profilename.txt" ) {
  345- &Error( "9530", "9531" );
  346- }
  347- }
  348- if ( -e "$UserProfileDir/$profilename.txt" ) {
  349- $profmod = "";
  350- open( FILE, "$UserProfileDir/$profilename.txt" );
  351- @message = <FILE>;
  352- close(FILE);
  353- foreach $line (@message) {
  354- if ( $line =~ /^MODERATED>(.*)/i ) {
  355- $profmod = $1;
  356- last;
  357- }
  358- }
  359- if ( $profmod eq "Yes" ) { $Moderated = 1; }
  360- if ( $profmod eq "No" ) {
  361- unless ($NaughtyModFlag) { $Moderated = 0; }
  362- }
  363- undef(@message);
  364- }
  365- if ($BannedIPsFile) {
  366- open( BANNED, "$BannedIPsFile" );
  367- @bannedips = <BANNED>;
  368- chomp(@bannedips);
  369- close(BANNED);
  370- foreach $bannedip (@bannedips) {
  371- $bannedip =~ s/^([^\s]*)\s.*$/$1/g;
  372- next if ( length($bannedip) < 2 );
  373- if (    ( $ENV{'REMOTE_HOST'} =~ /$bannedip/i )
  374-      || ( $ENV{'REMOTE_ADDR'} =~ /$bannedip/i ) )
  375- {
  376- if ( $BanLevel == 1 ) {
  377- $Moderated  = 1;
  378- $email_list = 1;
  379- last;
  380- }
  381- else {
  382- &Error( "9520", "9521" );
  383- }
  384- }
  385- }
  386- undef @bannedips;
  387- }
  388- if ($BanUnresolved) {
  389- if ( $ENV{'REMOTE_HOST'} =~ /^\d+\.\d+\.\d+\.\d+$/ ) {
  390- if ( $BanLevel == 1 ) {
  391- $Moderated  = 1;
  392- $email_list = 1;
  393- }
  394- else {
  395- &Error( "9520", "9521" );
  396- }
  397- }
  398- }
  399- if ($force_moderated) {
  400- $Moderated = 1;
  401- }
  402- if ( $FORM{'followup'} ) { $followup = int( $FORM{'followup'} ); }
  403- if ( $FORM{'subject'} )  { $subject  = "$FORM{'subject'}"; }
  404- $subject =~ s/\"\;/"/g;
  405- $subject =~ s/\<\;/</g;
  406- $subject =~ s/\>\;/>/g;
  407- $subject =~ s/\&\;/\&/g;
  408- $subject = substr( $subject, 0, $MaxInputLength );
  409- 
  410- if ( $subject
  411-      && ( %SmileyCode || $NM_Telltale || $Link_Telltale || $Pic_Telltale ) )
  412- {
  413- $realsubject = $subject;
  414- if (%SmileyCode) {
  415- foreach $key ( keys %SmileyCode ) {
  416- $key2 = $key;
  417- $key2    =~ s/([\[\]\(\)\\\*\+\?\\\|])/\\$1/g;
  418- $subject =~ s/(^$key2)|([ \n]$key2)/ $SmileyCode{$key}/g;
  419- }
  420- }
  421- if ( $NM_Telltale && ( length( $FORM{'body'} ) < 4 ) ) {
  422- $subject .= " $NM_Telltale";
  423- }
  424- if ( $Link_Telltale && $message_url ) {
  425- $subject .= " $Link_Telltale";
  426- }
  427- if ( $Pic_Telltale && $image_url ) {
  428- $subject .= " $Pic_Telltale";
  429- }
  430- }
  431- else {
  432- $subject =~ s/\&/\&\;/g;
  433- $subject =~ s/>/\>\;/g;
  434- $subject =~ s/</\<\;/g;
  435- $subject =~ s/"/\"\;/g;
  436- }
  437- 
  438- if ( $FORM{'editmsg'} ) {
  439- @SubjectPrefixes = ();
  440- }
  441- if ( $subject && @SubjectPrefixes && !($followup) ) {
  442- if ( $FORM{'subjectprefix'} ) {
  443- foreach $key (@SubjectPrefixes) {
  444- if ( $FORM{'subjectprefix'} eq $key ) {
  445- $PrefixOK = 1;
  446- last;
  447- }
  448- }
  449- if ($PrefixOK) {
  450- $ChosenPrefix = $FORM{'subjectprefix'};
  451- if (%SmileyCode) {
  452- foreach $key ( keys %SmileyCode ) {
  453- $key2 = $key;
  454- $key2         =~ s/([\[\]\(\)\\\*\+\?\\\|])/\\$1/g;
  455- $ChosenPrefix =~ s/(^$key2)|([ \n]$key2)/ $SmileyCode{$key}/g;
  456- }
  457- }
  458- $subject = $ChosenPrefix . " " . $subject;
  459- }
  460- else { $subject = ""; }
  461- }
  462- else { $subject = ""; }
  463- }
  464- else { $FORM{'subjectprefix'} = ""; }
  465- if ( $FORM{'body'} ) { $body = "$FORM{'body'}"; }
  466- if ($NaughtyFlag) {
  467- &Error( "9510", "9511" );
  468- }
  469- $msg_content = {};
  470- if ( $FORM{'editmsg'} ) {
  471- 
  472- if ($Moderated) {
  473- &Error( "9522", "9523.1" );
  474- }
  475- 
  476- my $file = $dir . '/bbs' . int( $FORM{'editmsg'} / 1000 ) . '/' . $FORM{'editmsg'};
  477- if ( !-s $file ) {
  478- $PreviewForm = undef;
  479- &Error( "9100", "9101" );
  480- }
  481- $msg_content = $read5x->read_message($file);
  482- my $time_now = time();
  483- my $edit_allowed = ( $msg_content->{'date'} + ( $AllowUserEditHours * 3600 ) ) - $time_now;
  484- if ( $edit_allowed <= 0 ) {
  485- &Error( "9522", "9523.1" );
  486- }
  487- my $PassCheck = $read5x->check_message_password( 'oldpassword' => $msg_content->{'oldpassword'},
  488-                                                  'password'    => $FORM{'password'}, );
  489- $name = $msg_content->{'poster_name'};
  490- 
  491- if ( !$PassCheck ) {
  492- $PassCheck = $read5x->check_profile_password( 'password'   => $FORM{'password'},
  493-                                               'username'   => $name,
  494-                                               'profiledir' => $data_basedir . '/_profiles',
  495- );
  496- }
  497- 
  498- if ( !$PassCheck ) {
  499- &Error( "9122", "9123" );
  500- }
  501- }
  502- elsif ( -e "$UserProfileDir/$profilename.txt" ) {
  503- if ( $FORM{'password'} ) {
  504- $password = crypt( $FORM{'password'}, "aa" );
  505- open( FILE, "$UserProfileDir/$profilename.txt" )
  506-     || &Error( "9110", "9111" );
  507- @profile = <FILE>;
  508- close(FILE);
  509- foreach $line (@profile) {
  510- if ( $line =~ /^PASSWORD>(.*)/i ) {
  511- $profilepassword = $1;
  512- last;
  513- }
  514- }
  515- undef(@profile);
  516- }
  517- else { &Error( "9120", "9121" ); }
  518- if ($profilepassword) {
  519- unless ( $password eq $profilepassword ) {
  520- &Error( "9120", "9121" );
  521- }
  522- }
  523- }
  524- if (    ( $name !~ /\S/ )
  525-      || ( $subject !~ /\S/ ) )
  526- {
  527- &Error( "9200", "9201" );
  528- }
  529- elsif (    ( !$FORM{'followup'} )
  530-         && @SubjectPrefixes
  531-         && (    ( !$FORM{'subjectprefix'} )
  532-              || ( $name !~ /\S/ )
  533-              || ( $subject !~ /\S/ ) )
  534-     )
  535- {
  536- &Error( "9200", "9202" );
  537- }
  538- if ( length($body) > ( $MaxMessageSize * 1024 ) ) {
  539- &Error( "9250", "9251" );
  540- }
  541- $picname  = "";
  542- $tempname = $name;
  543- $tempname =~ s/[^\w\.\-\']/\+/g;
  544- $tempname =~ tr/A-Z/a-z/;
  545- $Cleaned_tempname = $tempname;
  546- $Cleaned_tempname =~ s/([\[\]\(\)\\\*\+\?\\\|])/\\$1/g;
  547- if ( $FORM{'PostGraphic'} ) {
  548- &make_dir( $ENV{DOCUMENT_ROOT} . $html_basedir . '/images' );
  549- &make_dir($UserPicsDir);
  550- opendir( PICFILES, "$UserPicsDir" );
  551- @picfiles = readdir(PICFILES);
  552- closedir(PICFILES);
  553- foreach $picfile (@picfiles) {
  554- next if ( $picfile =~ /^\./ );
  555- next if ( $picfile =~ /^pic\d+\.gif$/ );
  556- next if ( $picfile =~ /^pic\d+\.jpg$/ );
  557- next if ( $picfile =~ /^pic\d+\.png$/ );
  558- if ( $picfile =~ /^pic$Cleaned_tempname/ ) {
  559- unlink "$UserPicsDir/$picfile";
  560- }
  561- elsif ( ( -M "$UserPicsDir/$picfile" ) > .5 ) {
  562- unlink "$UserPicsDir/$picfile";
  563- }
  564- }
  565- srand();
  566- $tag = int( rand(1000) );
  567- $tag = $tempname . $tag;
  568- if    ( $PicType eq "GIF" ) { $picname = "pic$tag.gif"; }
  569- elsif ( $PicType eq "JPG" ) { $picname = "pic$tag.jpg"; }
  570- elsif ( $PicType eq "PNG" ) { $picname = "pic$tag.png"; }
  571- else {
  572- &Error( "9650", "9651" );
  573- }
  574- if ( length( $FORM{'PostGraphic'} ) > ( $MaxGraphicSize * 1024 ) ) {
  575- &Error( "9652", "9653" );
  576- }
  577- unless ( open( GRAPHIC, ">$UserPicsDir/$picname" ) ) {
  578- &Error( "9654", "9655" );
  579- }
  580- binmode GRAPHIC;
  581- print GRAPHIC $FORM{'PostGraphic'};
  582- close(GRAPHIC);
  583- $image_url = "$UserPicsURL/$picname";
  584- if ( $Pic_Telltale && !( $subject =~ /$Cleaned_Pic_Telltale/ ) ) {
  585- $subject .= " $Pic_Telltale";
  586- }
  587- }
  588- if ( $FORM{'Preview'} ) {
  589- &PreviewPost;
  590- }
  591- 
  592- if ( !$FORM{'editmsg'} ) {
  593- $new_body = $name . $email . $subject . $body . $image_url . $message_url_title . $message_url;
  594- $new_body =~ s/\n/ /g;
  595- unless ( -w "$dir" ) { &Error( "9410", "9411" ); }
  596- open( DUPEDATA, "$dir/dupecheck.txt" );
  597- $last_body = <DUPEDATA>;
  598- close(DUPEDATA);
  599- if ( $last_body eq $new_body ) { &Error( "9500", "9501" ); }
  600- else {
  601- open( DUPEDATA, ">$dir/dupecheck.txt" );
  602- print DUPEDATA "$new_body";
  603- close(DUPEDATA);
  604- }
  605- 
  606- $num = $tbb->{'db'}->{'db_main'}->get_new_messagenumber();
  607- if ( !$num ) {
  608- $tbb->send_error_plain( "89400", "89401" );
  609- exit;
  610- }
  611- 
  612- if ($PRO::VERSION) {
  613- my $href = &PRO::cb_message_post_3( 'tbb'      => $main::tbb,
  614-                                     'board_id' => $main::tbb->{'conf'}->{'board_id'},
  615-                                     'msg_num'  => $num,
  616-                                     'formid'   => $FORM{'formid'},
  617-                                     'body'     => $body,
  618- );
  619- if ( $href->{'body'} ) { $body = $href->{'body'}; }
  620- if (    $href->{'media_count'}
  621-      && $Pic_Telltale
  622-      && !( $subject =~ /$Cleaned_Pic_Telltale/ ) )
  623- {
  624- $subject .= " $Pic_Telltale";
  625- }
  626- }
  627- 
  628- }
  629- else {
  630- $num = $FORM{'editmsg'};
  631- if ($PRO::VERSION) {
  632- my $href = &PRO::cb_message_edit_2( 'tbb'      => $main::tbb,
  633-                                     'board_id' => $main::tbb->{'conf'}->{'board_id'},
  634-                                     'msg_num'  => $num,
  635-                                     'formid'   => $FORM{'formid'},
  636-                                     'body'     => $body,
  637- );
  638- if ( $href->{'body'} ) { $body = $href->{'body'}; }
  639- if (    $href->{'media_count'}
  640-      && $Pic_Telltale
  641-      && !( $subject =~ /$Cleaned_Pic_Telltale/ ) )
  642- {
  643- $subject .= " $Pic_Telltale";
  644- }
  645- }
  646- }
  647- if ( $image_url =~ /$Cleaned_tempname/ ) {
  648- $tag = "";
  649- $image_url =~ s/$Cleaned_tempname(\d+)\.gif/$num\.gif/g;
  650- if ($1) { $tag = $1; }
  651- $image_url =~ s/$Cleaned_tempname(\d+)\.jpg/$num\.jpg/g;
  652- if ($1) { $tag = $1; }
  653- $image_url =~ s/$Cleaned_tempname(\d+)\.png/$num\.png/g;
  654- if ($1) { $tag = $1; }
  655- rename( "$UserPicsDir/pic$tempname$tag.gif", "$UserPicsDir/pic$num.gif" );
  656- rename( "$UserPicsDir/pic$tempname$tag.jpg", "$UserPicsDir/pic$num.jpg" );
  657- rename( "$UserPicsDir/pic$tempname$tag.png", "$UserPicsDir/pic$num.png" );
  658- }
  659- 
  660- my $datafile = '';
  661- if ($Moderated) {
  662- &make_dir("$dir/_modbin");
  663- $datafile = $dir . '/_modbin/' . $num;
  664- }
  665- else {
  666- $subdir = "bbs" . int( $num / 1000 );
  667- &make_dir("$dir/$subdir");
  668- $datafile = $dir . '/' . $subdir . '/' . $num;
  669- }
  670- 
  671- $date = $msg_content->{'date'} || $todaydate;
  672- if ( $msg_content->{'previous'} ) {
  673- $followup = $msg_content->{'previous'};
  674- }
  675- $next = $msg_content->{'next'} || '';
  676- 
  677- open( MESSAGE, ">$datafile" )
  678-     || &Error( "9400", "9401", "$dir/$subdir/$num" );
  679- print MESSAGE "SUBJECT>$subject\n";
  680- print MESSAGE "POSTER>$name\n";
  681- print MESSAGE "EMAIL>$email\n";
  682- print MESSAGE "DATE>$date\n";
  683- unless ( $FORM{'wantnotice'} ) {
  684- print MESSAGE "EMAILNOTICES>no\n";
  685- }
  686- print MESSAGE "IP_ADDRESS>$ENV{'REMOTE_HOST'}\n";
  687- if ( $ENV{'REMOTE_USER'} ) {
  688- print MESSAGE "<!--$ENV{'REMOTE_USER'}-->\n";
  689- }
  690- if ( $FORM{'password'} ) {
  691- $password = crypt( $FORM{'password'}, "aa" );
  692- print MESSAGE "PASSWORD>$password\n";
  693- }
  694- print MESSAGE "PREVIOUS>$followup\n";
  695- print MESSAGE "NEXT>$next\n";
  696- print MESSAGE "IMAGE>$image_url\n";
  697- print MESSAGE "LINKNAME>$message_url_title\n";
  698- print MESSAGE "LINKURL>$message_url\n";
  699- print MESSAGE "$body\n";
  700- close(MESSAGE);
  701- 
  702- if ( !$main::tbb->{'conf'}->{'search'}->{'enable'} ) {
  703- if ( $FORM{'editmsg'} ) {
  704- open( SEARCH, "$dir/searchterms.idx" );
  705- &LockOpen( NEWSEARCH, "$dir/newsearchterms.idx" );
  706- while (<SEARCH>) {
  707- if (/^(\d+) /) {
  708- my $message = $1;
  709- $subdir = "bbs" . int( $message / 1000 );
  710- if ( ( -e "$dir/$subdir/$message" ) && ( $message ne $num ) ) {
  711- print NEWSEARCH "$_";
  712- }
  713- }
  714- }
  715- close(SEARCH);
  716- &LockClose( NEWSEARCH, "$dir/newsearchterms.idx" );
  717- rename( "$dir/newsearchterms.idx", "$dir/searchterms.idx" )
  718-     || die "rename failed";
  719- 
  720- }
  721- if (    ( !$Moderated )
  722-      && ( !$main::tbb->{'conf'}->{'search'}->{'enable'} ) )
  723- {
  724- %wordlist = ();
  725- @words    = ();
  726- &LockOpen( SEARCH, "$dir/searchterms.idx", "a" );
  727- print SEARCH "$num ";
  728- $line = "$subject $name $body";
  729- $line =~ s/<([^>]|\n)*(>|$)/ /g;
  730- 
  731- $line =~ tr/A-Z/a-z/;
  732- 
  733- $line =~ s/&[^;\s]*;/ /g;
  734- $line = &prepare_searchindex($line);
  735- $line =~ s/(\s)+/ /g;
  736- @words = split( /\s/, $line );
  737- foreach $word (@words) {
  738- next if ( $wordlist{$word} );
  739- $wordlist{$word} = 1;
  740- print SEARCH "$word ";
  741- }
  742- print SEARCH "\n";
  743- &LockClose( SEARCH, "$dir/searchterms.idx" );
  744- }
  745- }
  746- 
  747- if ( !$FORM{'editmsg'} ) {
  748- if ($followup) {
  749- if ($Moderated) {
  750- $fudate = $fusub = $fuposter = $fuprev = $funext = $fucount = $fuadmin = $fuip = "";
  751- ( $fudate, $fusub, $fuposter, $fuprev, $funext, $fucount, $fuadmin, $fuip ) = split( /\|/, $MessageList{$followup} );
  752- }
  753- else {
  754- $subdir = "bbs" . int( $followup / 1000 );
  755- open( FOLLOWUP, "$dir/$subdir/$followup" );
  756- @followup_lines = <FOLLOWUP>;
  757- chomp(@followup_lines);
  758- close(FOLLOWUP);
  759- open( FOLLOWUP, ">$dir/$subdir/$followup" );
  760- foreach $line (@followup_lines) {
  761- if ( $line =~ /^EMAILNOTICES>/i ) {
  762- $fuwantnotice = "no";
  763- }
  764- elsif ( $line =~ /^EMAIL>(.*)/i ) {
  765- $fuemail = $1;
  766- }
  767- if ( $line =~ /^NEXT>/ ) {
  768- print FOLLOWUP "$line $num\n";
  769- }
  770- else {
  771- print FOLLOWUP "$line\n";
  772- }
  773- }
  774- close(FOLLOWUP);
  775- $fudate = $fusub = $fuposter = $fuprev = $funext = $fucount = $fuadmin = $fuip = "";
  776- ( $fudate, $fusub, $fuposter, $fuprev, $funext, $fucount, $fuadmin, $fuip ) = split( /\|/, $MessageList{$followup} );
  777- $funext .= " $num";
  778- delete( $MessageList{$followup} );
  779- foreach $key ( $fudate, $fusub, $fuposter, $fuprev, $funext, $fucount, $fuadmin, $fuip ) {
  780- $MessageList{$followup} .= "$key|";
  781- }
  782- }
  783- $fusub    =~ s/&pipe;/\|/g;
  784- $fuposter =~ s/&pipe;/\|/g;
  785- }
  786- if ($mailprog) {
  787- if ( $FORM{'subjectprefix'} ) {
  788- $mailsubject = $FORM{'subjectprefix'} . " ";
  789- $mailsubject .= $FORM{'subject'};
  790- $FORM{'subject'} = $mailsubject;
  791- }
  792- $FORM{'subject'} = &UnWebify( $FORM{'subject'} );
  793- if ( length( $FORM{'subject'} ) > 50 ) {
  794- $FORM{'subject'} = substr( $FORM{'subject'}, 0, 46 );
  795- $FORM{'subject'} .= "....";
  796- }
  797- $FORM{'name'} = &UnWebify( $FORM{'name'} );
  798- if ( length( $FORM{'name'} ) > 15 ) {
  799- $FORM{'name'} = substr( $FORM{'name'}, 0, 11 );
  800- $FORM{'name'} .= "....";
  801- }
  802- $FORM{'body'} .= "\n";
  803- $FORM{'body'} = &UnWebify( $FORM{'body'} );
  804- $message_url_title = &UnWebify($message_url_title);
  805- if ($Moderated) {
  806- $body = $text{'7005'} . "\r\n\r\n" . $text{'7001'} . "\r\n\r\n";
  807- }
  808- else {
  809- $body = $text{'7000'} . "\r\n\r\n" . $text{'7001'} . "\r\n\r\n";
  810- }
  811- $body .= "$text{'7600'} (#$num) $FORM{'subject'}\r\n";
  812- unless ($Moderated) {
  813- $body .= "$text{'7603'} <";
  814- $body .= $longcgiurl . $QS0 . "rev" . $QS2 . "$num>\r\n";
  815- }
  816- $body .= "$text{'7601'} $FORM{'name'}";
  817- $body .= "\r\n";
  818- $body .= "$text{'7602'} ";
  819- $body .= &PrintDate($todaydate) . "\r\n\r\n";
  820- if ($followup) {
  821- $subjectfu = &UnWebify($fusub);
  822- if ( length($subjectfu) > 50 ) {
  823- $subjectfu = substr( $subjectfu, 0, 46 );
  824- $subjectfu .= "....";
  825- }
  826- $posterfu = &UnWebify($fuposter);
  827- if ( length($posterfu) > 15 ) {
  828- $posterfu = substr( $posterfu, 0, 11 );
  829- $posterfu .= "....";
  830- }
  831- $body .= "$text{'7604'} (#$followup) $subjectfu\r\n";
  832- $body .= "$text{'7605'} $posterfu\r\n";
  833- $body .= "$text{'7606'} ";
  834- $body .= &PrintDate($fudate) . "\r\n\r\n";
  835- }
  836- unless ($HeaderOnly) {
  837- $body .= $FORM{'body'} . "\r\n";
  838- if ( $message_url && $message_url_title ) {
  839- $body .= "$text{'7607'} $message_url_title\r\n";
  840- $body .= "$text{'7608'} <$message_url>\r\n\r\n";
  841- }
  842- if ($image_url) {
  843- $body .= "$text{'7609'} <$image_url>\r\n\r\n";
  844- }
  845- }
  846- $body .= $text{'7001'} . "\r\n\r\n" . $text{'7002'};
  847- unless ($ArchiveOnly) {
  848- $body .= "  " . $text{'7003'};
  849- }
  850- $body .= "\r\n\r\n";
  851- @bodylines = split( /\n/, $body );
  852- $body = "";
  853- foreach $bodyline (@bodylines) {
  854- if ( $bodyline =~ /^\./ ) {
  855- $bodyline = "." . $bodyline;
  856- }
  857- $quotewrap = 0;
  858- @quotedwords = split( /\s/, $bodyline );
  859- foreach $quotedword (@quotedwords) {
  860- $quotewrap += length($quotedword) + 1;
  861- if ( $quotewrap > 79 ) {
  862- if ( $quotedword =~ /^\./ ) {
  863- $body .= "\r\n.$quotedword ";
  864- }
  865- else {
  866- $body .= "\r\n$quotedword ";
  867- }
  868- $quotewrap = length($quotedword) + 1;
  869- }
  870- else {
  871- $body .= "$quotedword ";
  872- }
  873- }
  874- $body .= "\r\n";
  875- }
  876- $bcc = "";
  877- if ($Moderated) {
  878- &SendMail;
  879- }
  880- else {
  881- if ( ( $email_list == 1 ) || $private_list ) {
  882- if ( -e "$dir/addresses.txt" ) {
  883- open( ADDRESSES, "$dir/addresses.txt" );
  884- @addresses = <ADDRESSES>;
  885- chomp(@addresses);
  886- close(ADDRESSES);
  887- foreach $address (@addresses) {
  888- unless (    ( $address =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|,|;|\// || $address !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,6}|[0-9]{1,3})(\]?)$/ )
  889-          || ( $email && ( $address =~ /$email/i ) )
  890-          || ( $fuemail
  891-               && ( $address =~ /$fuemail/i ) )
  892-     )
  893- {
  894- $bcc .= ", " . $address;
  895- }
  896- if ( $fuemail
  897-      && ( $address =~ /$fuemail/i ) )
  898- {
  899- $onrecipientlist = 1;
  900- }
  901- }
  902- $bcc =~ s/^, //;
  903- }
  904- &SendMail;
  905- }
  906- if ($fuemail) {
  907- $bcc = "";
  908- unless (    ( ( $email_list == 1 ) || $private_list )
  909-          && ( $fuemail eq $notification_address ) )
  910- {
  911- unless (    ( ( $fuwantnotice eq "no" ) && !$onrecipientlist )
  912-          || ( $fuemail eq $email ) )
  913- {
  914- &SendMail($fuemail);
  915- }
  916- }
  917- }
  918- }
  919- }
  920- }
  921- 
  922- $count = "";
  923- unless ( $FORM{'Admin'} eq "AdminPost" ) { $FORM{'Admin'} = ""; }
  924- delete( $MessageList{$num} );
  925- unless ($Moderated) {
  926- $subject =~ s/\|/&pipe;/g;
  927- $name    =~ s/\|/&pipe;/g;
  928- foreach $key ( $date, $subject, $name, $followup, $next, $count, $FORM{'Admin'}, $ENV{'REMOTE_HOST'} ) {
  929- $MessageList{$num} .= "$key|";
  930- }
  931- }
  932- 
  933- if ($PRO::VERSION) {
  934- &PRO::cb_message_post_4( 'tbb'         => $main::tbb,
  935-                          'msg_num'     => $num,
  936-                          'tied_db_ref' => \%MessageList,
  937- );
  938- }
  939- 
  940- my $refresh_anchor = $followup || $num;
  941- 
  942- if ($Moderated) {
  943- &Header( $text{'1600'}, $MessageHeaderFile, "refreshalways" );
  944- }
  945- else {
  946- &Header( $text{'1600'}, $MessageHeaderFile, "refreshalways", "$refresh_anchor" );
  947- }
  948- 
  949- my %subnav_args = ( 'msg_num'        => $num,
  950-                     'refresh_anchor' => $refresh_anchor,
  951-                     'moderated'      => $Moderated,
  952- );
  953- ( $navbar_top, $navbar_bottom ) =
  954-     $main::tbb->{'tbb_html'}->get_navbar_HTML( 'sub_navbar'  => 'post',
  955-                                                'subnav_args' => \%subnav_args,
  956-                                                'refresh_url' => 'auto',
  957-     );
  958- unless ($TopNavbarNoPrint) {
  959- print "<div id='nb_top'>\n" . $navbar_top . "</div>\n";
  960- }
  961- print "<div id='glob_header'>\n", $cust{'glob_header_s'};
  962- if ($printboardname) {
  963- print "<h2>$boardname</h2>\n";
  964- }
  965- print "<h3>$text{'1600'}</h3>\n";
  966- print "$cust{'glob_header_e'}</div>\n";
  967- if ( $cust{'msg_thanks_01'} ) {
  968- print $cust{'msg_thanks_01'}, "\n";
  969- }
  970- print "<div id='misc_refpages'>\n";
  971- if ($ShowPosterIP) {
  972- print '<p>', $text{'1602'}, ': ', $ENV{'REMOTE_ADDR'};
  973- unless ( $ENV{'REMOTE_HOST'} eq $ENV{'REMOTE_ADDR'} ) {
  974- $ENV{'REMOTE_HOST'} =~ s/[^\.]*\.(.*)/$1/;
  975- print "<br>\n$text{'1603'}: $ENV{'REMOTE_HOST'}";
  976- }
  977- print "</p>\n";
  978- }
  979- print "<p>$text{'1601'}</p>\n";
  980- if ($Moderated) {
  981- print "<p>$text{'1700'}</p>\n";
  982- }
  983- print "</div>\n";
  984- if ( $cust{'msg_thanks_02'} ) {
  985- print $cust{'msg_thanks_02'}, "\n";
  986- }
  987- &Footer( $MessageFooterFile, "return", "refreshalways" );
  988- } ## end sub PostMessage
  989- 
  990- sub PreviewPost {
  991- $SpellCheckerMeta = 1;
  992- &Header( $text{'2000'}, $MessageHeaderFile );
  993- &Header2;
  994- print "<h3>$text{'2000'}</h3>\n";
  995- print $cust{'glob_header_e'}, "</div>\n";
  996- print "<p>$text{'2001'}</p>\n", "<div id='msg_wrap'>\n", "<div class='msg_headln'>\n", $cust{'msg_headln_s'}, $subject, $cust{'msg_headln_e'}, "</div>\n", "<div class=\"msg_userln\">\n", "$text{'1000'} <span class=\"msg_poster\">$name</span>";
  997- if ( $DisplayEmail && $email ) {
  998- print " <span class=\"msg_email\"><";
  999- if   ($BlindEmail) { print "$text{'1050'}"; }
 1000- else               { print "$email"; }
 1001- print "></span>";
 1002- }
 1003- print "<br>\n$text{'1001'} <span class=\"msg_date\">", &PrintDate($todaydate), "</span>\n</div>\n";
 1004- if ( $MessageList{$followup} > 0 ) {
 1005- $pdate = $psub = $pposter = $pprev = $pnext = $pcount = $padmin = $pip = "";
 1006- ( $pdate, $psub, $pposter, $pprev, $pnext, $pcount, $padmin, $pip ) =
 1007-     split( /\|/, $MessageList{$followup} );
 1008- $psub    =~ s/&pipe;/\|/g;
 1009- $pposter =~ s/&pipe;/\|/g;
 1010- print "<div class=\"msg_prev\">\n$text{'1002'} ";
 1011- print "<span class=\"msg_subject\">";
 1012- print "$psub ($pposter)</span></div>\n";
 1013- }
 1014- print "<div class=\"msg_text\">\n$MessageOpenCode\n";
 1015- print "$body $MessageCloseCode\n</div>\n";
 1016- if ($image_url) {
 1017- print "<div class=\"msg_image\">\n";
 1018- print "<IMG SRC=\"$image_url\" ALT=\"\"><div>\n";
 1019- }
 1020- if ($message_url) {
 1021- print "<div class=\"msg_link\">\n";
 1022- print "<a href=\"$message_url\" ";
 1023- print "target=\"_blank\">";
 1024- print "$message_url_title</a></div>\n";
 1025- }
 1026- print "</div>\n";
 1027- $body = $BodyPreview;
 1028- $body =~ s/\& /\&\; /g;
 1029- $body =~ s/"/\"\;/g;
 1030- $body =~ s/</\<\;/g;
 1031- $body =~ s/>/\>\;/g;
 1032- if ($realsubject) {
 1033- $subject = $realsubject;
 1034- $subject =~ s/\& /\&\; /g;
 1035- $subject =~ s/"/\"\;/g;
 1036- $subject =~ s/</\<\;/g;
 1037- $subject =~ s/>/\>\;/g;
 1038- }
 1039- require 'webbbs_form.pl';
 1040- print "<div id='misc_msgform'>\n", $cust{'misc_msgform_s'};
 1041- &Print_Form(-1);
 1042- print $cust{'misc_msgform_e'}, "</div>\n";
 1043- &Footer( $MessageFooterFile, "credits", 'nonavbar' );
 1044- } ## end sub PreviewPost
 1045- 
 1046- sub UnWebify {
 1047- $texttoconvert = $_[0];
 1048- $texttoconvert =~ s/<P>/\n\n/g;
 1049- $texttoconvert =~ s/<[^>]*\s+ALT\s*=\s*"(([^>"])*)"[^>]*>/$1/ig;
 1050- $texttoconvert =~ s/<([^>]|\n)*>//g;
 1051- $texttoconvert =~ s/\"\;/"/g;
 1052- $texttoconvert =~ s/\<\;/</g;
 1053- $texttoconvert =~ s/\>\;/>/g;
 1054- $texttoconvert =~ s/\&\;/\&/g;
 1055- $texttoconvert =~ s/\n(\n)+/\n\n/g;
 1056- $texttoconvert =~ s/^\n*//g;
 1057- $texttoconvert =~ s/\n+$/\n/g;
 1058- return $texttoconvert;
 1059- } ## end sub UnWebify
 1060- 
 1061- sub SendMail {
 1062- local ($To) = $_[0];
 1063- return unless ($mailprog);
 1064- if ( $Moderated && !($AdminRun) && !($MailPassword) ) {
 1065- return unless ($NotifyAdminOnModerated);
 1066- $ModMail = 1;
 1067- }
 1068- if ( $ModMail || !($To) ) { $To = $notification_address; }
 1069- unless ($ReplyToAddress) { $ReplyToAddress = $maillist_address; }
 1070- return unless $To;
 1071- if    ($ModMail)      { $email_subject = $text{'0703'}; }
 1072- elsif ($MailPassword) { $email_subject = "$text{'2651'}"; }
 1073- else                  { $email_subject = $FORM{'subject'}; }
 1074- 
 1075- my $debug = $main::DebugSMTP || 0;
 1076- my %mail_data = ( 'mailprog'      => $mailprog,
 1077-                   'smtp_server'   => $main::SMTP_SERVER,
 1078-                   'smtp_user'     => $main::SMTP_USER,
 1079-                   'smtp_password' => $main::SMTP_PASSWORD,
 1080-                   'debug_smtp'    => $debug,
 1081-                   'sender'        => $main::maillist_address,
 1082-                   'text'          => $body,
 1083- );
 1084- if ( $ModMail && $email ) {
 1085- $mail_data{'reply'} = $email;
 1086- }
 1087- else {
 1088- $mail_data{'reply'} = $ReplyToAddress;
 1089- }
 1090- if ( $BlindEmailSend || ( !$shortboardname ) ) {
 1091- $mail_data{'subject'} = $email_subject;
 1092- }
 1093- else {
 1094- $mail_data{'subject'} = "[$shortboardname:] " . $email_subject;
 1095- }
 1096- foreach my $key ( keys %mail_data ) {
 1097- $mail_data{$key} =~ s/\||\`|\íŽ//g;
 1098- }
 1099- my @addresses = ($To);
 1100- if ($bcc) {
 1101- my @bcc = split( /, */, $bcc );
 1102- push( @addresses, @bcc );
 1103- undef @bcc;
 1104- }
 1105- my @valid_addresses = ();
 1106- while ( my $address = shift @addresses ) {
 1107- chomp $address;
 1108- next if $address =~ /^\s*$/;
 1109- eval ' $basic->validate_email($address); ';
 1110- next if $@;
 1111- push( @valid_addresses, $address );
 1112- }
 1113- my %dupcheck = ();
 1114- @valid_addresses = grep { $dupcheck{$_}++ == 0 } @valid_addresses;
 1115- undef %dupcheck;
 1116- while ( $mail_data{'recipient'} = shift @valid_addresses ) {
 1117- if ( ( $mailprog eq 'SMTP' ) || ( $mailprog eq 'libnet' ) ) {
 1118- my $result = $basic->send_smtp(%mail_data);
 1119- if ( !$result ) {
 1120- warn "SMTP error sending digest mail to $mail_data{'recipient'}\n";
 1121- next;
 1122- }
 1123- }
 1124- elsif ($mailprog) {
 1125- eval ' $basic->send_mail(%mail_data); ';
 1126- if ($@) {
 1127- warn "Sendmail error sending digest mail to $mail_data{'recipient'}, error reportet: $@\n";
 1128- next;
 1129- }
 1130- }
 1131- }
 1132- } ## end sub SendMail
 1133- 
 1134- sub SetCookieData {
 1135- &GetCookie($boardname);
 1136- unless ( $FORM{'password'} )   { $FORM{'password'}      = $Cookies{'password'}; }
 1137- unless ( $FORM{'wantnotice'} ) { $Cookies{'wantnotice'} = "no"; }
 1138- else                           { $Cookies{'wantnotice'} = "yes"; }
 1139- $listtype = $Cookies{'listtype'};
 1140- $listtime = $Cookies{'listtime'};
 1141- 
 1142- unless ( $Cookies{'lastvisit'} ) {
 1143- $Cookies{'lastvisit'}   = $lastvisit = $todaydate;
 1144- $Cookies{'lastmessage'} = $lastseen  = $lastmessage;
 1145- $Cookies{'thisvisit'}   = $thisvisit = $todaydate;
 1146- $Cookies{'thismessage'} = $thisseen  = $lastmessage;
 1147- }
 1148- if ( $Cookies{'timestamp'}
 1149-      && ( ( $time - $Cookies{'timestamp'} ) > $SessionTime ) )
 1150- {
 1151- $Cookies{'lastvisit'}   = $lastvisit = $Cookies{'thisvisit'};
 1152- $Cookies{'lastmessage'} = $lastseen  = $Cookies{'thismessage'};
 1153- $Cookies{'thisvisit'}   = $thisvisit = $todaydate;
 1154- $Cookies{'thismessage'} = $thisseen  = $lastmessage;
 1155- }
 1156- else {
 1157- $lastvisit = $Cookies{'lastvisit'};
 1158- $lastseen  = $Cookies{'lastmessage'};
 1159- $thisvisit = $Cookies{'thisvisit'};
 1160- $thisseen  = $Cookies{'thismessage'};
 1161- }
 1162- &WriteCookie;
 1163- } ## end sub SetCookieData
 1164- 1;