--- a/branches/2.6/cgi-bin/yabb2/Sources/MyCenter.pm
+++ b/branches/2.6/cgi-bin/yabb2/Sources/MyCenter.pm
@@ -18,7 +18,7 @@
 use CGI::Carp qw(fatalsToBrowser);
 our $VERSION = '2.6.0';
 
-$mycenterpmver = 'YaBB 2.6.0 $Revision: 1471 $';
+$mycenterpmver = 'YaBB 2.6.0 $Revision: 1473 $';
 if ( $action eq 'detailedversion' ) { return 1; }
 
 LoadLanguage('InstantMessage');
@@ -550,7 +550,6 @@
     fopen( USRFILE, "<$memberdir/$fileToOpen" );
     my @messages = <USRFILE>;
     fclose( USRFILE );
-    my @delusr = ();
 
     # deleting
     if (   $FORM{'imaction'} eq $inmes_txt{'remove'}
@@ -568,7 +567,7 @@
         if ( $INFO{'deleteid'} ) {
             $FORM{ 'message' . $INFO{'deleteid'} } = 1;
         }    # single delete
-
+        fopen( USRFILE, ">$memberdir/$fileToOpen" );
         foreach (@messages) {
             my @m = split /\|/xsm, $_;
             chomp @m;
@@ -581,9 +580,9 @@
                 }
             }
             if ( !exists $FORM{ 'message' . $m[0] } ) {
-			    fopen( USRFILE, ">$memberdir/$fileToOpen" );
+
                 print {USRFILE} $_ or croak "$croak{'print'} USRFILE";
-		        fclose(USRFILE);
+
 
                 if    ( $INFO{'caller'} == 2 ) { ${$username}{'PMmoutnum'}++; }
                 elsif ( $INFO{'caller'} == 3 ) { $CountStore{ $m[13] }++; }
@@ -604,6 +603,7 @@
                 }
             }
         }
+        fclose(USRFILE);
         if ( $INFO{'caller'} == 3 ) {
             ${$username}{'PMfoldersCount'} = q{};
             ${$username}{'PMstorenum'}     = 0;
@@ -629,11 +629,11 @@
         }
         elsif ( $INFO{'caller'} == 1 ) { $imstorefolder = 'in'; }
         else                           { $imstorefolder = 'out'; }
-
+        fopen( USRFILE, ">$memberdir/$fileToOpen" );
         foreach (@messages) {
             if ( !$FORM{ 'message' . ( split /\|/xsm, $_, 2 )[0] } ) {
                 if ( $INFO{'caller'} != 3 ) {
-                    push @delusr, $_;
+                    print {USRFILE} $_ or croak "$croak{'print'} USRFILE";
                 }
                 else {
                     my @m = split /\|/xsm, $_;
@@ -656,8 +656,6 @@
                 }
             }
         }
-        fopen( USRFILE, ">$memberdir/$fileToOpen" );
-        print {USRFILE} @delusr or croak "$croak{'print'} USRFILE";
         fclose(USRFILE);
 
         if (@newmessages) {