#!/usr/bin/perl # $Header: /mhub4/sources/imap-tools/imapsync.pl,v 1.6 2010/01/08 14:27:39 rick Exp $ ####################################################################### # Program name imapsync.pl # # Written by Rick Sanders # # # # Description # # # # imapsync is a utility for synchronizing a user's account on two # # IMAP servers. When supplied with host/user/password information # # for two IMAP hosts imapsync does the following: # # 1. Adds any messages on the 1st host which aren't on the 2nd # # 2. Deletes any messages from the 2nd which aren't on the 1st # # 3. Sets the message flags on the 2nd to match the 1st's flags# # # # imapsync is called like this: # # ./imapsync -S host1/user1/password1 -D host2/user2/password2 # # # # Optional arguments: # # -d debug # # -L logfile # # -m mailbox list (sync only certain mailboxes,see usage notes) # ####################################################################### use Socket; use IO::Socket; use IO::Socket::INET; use FileHandle; use Fcntl; use Getopt::Std; ################################################################# # Main program. # ################################################################# init(); # Get list of all messages on the source host by Message-Id # connectToHost($sourceHost, \$src) or exit; login($sourceUser,$sourcePwd, $src) or exit; namespace( $src, \$srcPrefix, \$srcDelim, $opt_x ); connectToHost( $destHost, \$dst ) or exit; login( $destUser,$destPwd, $dst ) or exit; namespace( $dst, \$dstPrefix, \$dstDelim, $opt_y ); # Create mailboxes on the dst if they don't already exist my @source_mbxs = getMailboxList( $src ); createDstMbxs( \@source_mbxs, $dst ); # Check for new messages and existing ones with new flags $adds=$updates=$deletes=0; ($added,$updated) = check_for_adds( \@source_mbxs, $src, $dst ); # Remove messages from the dst that no longer exist on the src $deleted = check_for_deletes( $dst, $src ); logout( $src ); logout( $dst ); Log("\nSummary of results"); Log(" Added $added"); Log(" Updated $updated"); Log(" Deleted $deleted"); exit; sub init { $os = $ENV{'OS'}; processArgs(); $timeout = 60 unless $timeout; # Open the logFile # if ( $logfile ) { if ( !open(LOG, ">> $logfile")) { print STDOUT "Can't open $logfile: $!\n"; } select(LOG); $| = 1; } Log("$0 starting\n"); # Determine whether we have SSL support via openSSL and IO::Socket::SSL $ssl_installed = 1; eval 'use IO::Socket::SSL'; if ( $@ ) { $ssl_installed = 0; } $debug = 1; } # # sendCommand # # This subroutine formats and sends an IMAP protocol command to an # IMAP server on a specified connection. # sub sendCommand { local($fd) = shift @_; local($cmd) = shift @_; print $fd "$cmd\r\n"; if ($showIMAP) { Log (">> $cmd",2); } } # # readResponse # # This subroutine reads and formats an IMAP protocol response from an # IMAP server on a specified connection. # sub readResponse { local($fd) = shift @_; $response = <$fd>; chop $response; $response =~ s/\r//g; push (@response,$response); if ($showIMAP) { Log ("<< $response",2); } } # # Log # # This subroutine formats and writes a log message to STDERR. # sub Log { my $str = shift; # If a logfile has been specified then write the output to it # Otherwise write it to STDOUT if ( $logfile ) { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime; if ($year < 99) { $yr = 2000; } else { $yr = 1900; } $line = sprintf ("%.2d-%.2d-%d.%.2d:%.2d:%.2d %s %s\n", $mon + 1, $mday, $year + $yr, $hour, $min, $sec,$$,$str); print LOG "$line"; } else { print STDOUT "$str\n"; } print STDOUT "$str\n"; } # insertMsg # # This routine inserts an RFC822 messages into a user's folder # sub insertMsg { local ($conn, $mbx, *message, $flags, $date) = @_; local ($lenx); Log(" Inserting message") if $debug; $lenx = length($message); $totalBytes = $totalBytes + $lenx; $totalMsgs++; $flags = flags( $flags ); sendCommand ($conn, "1 APPEND \"$mbx\" ($flags) \"$date\" \{$lenx\}"); readResponse ($conn); if ( $response !~ /^\+/ ) { Log ("unexpected APPEND response: $response"); # next; push(@errors,"Error appending message to $mbx for $user"); return 0; } print $conn "$message\r\n"; undef @response; while ( 1 ) { readResponse ($conn); if ( $response =~ /^1 OK/i ) { last; } elsif ( $response !~ /^\*/ ) { Log ("unexpected APPEND response: $response"); # next; return 0; } } return 1; } # Make a connection to an IMAP host sub connectToHost { my $host = shift; my $conn = shift; Log("Connecting to $host") if $verbose; ($host,$port) = split(/:/, $host); $port = 143 unless $port; # We know whether to use SSL for ports 143 and 993. For any # other ones we'll have to figure it out. $mode = sslmode( $host, $port ); if ( $mode eq 'SSL' ) { unless( $ssl_installed == 1 ) { warn("You must have openSSL and IO::Socket::SSL installed to use an SSL connection"); Log("You must have openSSL and IO::Socket::SSL installed to use an SSL connection"); exit; } Log("Attempting an SSL connection") if $verbose; $$conn = IO::Socket::SSL->new( Proto => "tcp", SSL_verify_mode => 0x00, PeerAddr => $host, PeerPort => $port, ); unless ( $$conn ) { $error = IO::Socket::SSL::errstr(); Log("Error connecting to $host: $error"); warn("Error connecting to $host: $error"); exit; } } else { # Non-SSL connection Log("Attempting a non-SSL connection") if $debug; $$conn = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $host, PeerPort => $port, ); unless ( $$conn ) { Log("Error connecting to $host:$port: $@"); exit; } } Log("Connected to $host on port $port"); } sub sslmode { my $host = shift; my $port = shift; my $mode; # Determine whether to make an SSL connection # to the host. Return 'SSL' if so. if ( $port == 143 ) { # Standard non-SSL port return ''; } elsif ( $port == 993 ) { # Standard SSL port return 'SSL'; } unless ( $ssl_installed ) { # We don't have SSL installed on this machine return ''; } # For any other port we need to determine whether it supports SSL my $conn = IO::Socket::SSL->new( Proto => "tcp", SSL_verify_mode => 0x00, PeerAddr => $host, PeerPort => $port, ); if ( $conn ) { close( $conn ); $mode = 'SSL'; } else { $mode = ''; } return $mode; } # trim # # remove leading and trailing spaces from a string sub trim { local (*string) = @_; $string =~ s/^\s+//; $string =~ s/\s+$//; return; } # login # # login in at the source host with the user's name and password # sub login { my $user = shift; my $pwd = shift; my $conn = shift; sendCommand ($conn, "1 LOGIN $user $pwd"); while (1) { readResponse ( $conn ); last if $response =~ /^1 OK/i; if ($response =~ /^1 NO|^1 BAD/i) { Log ("unexpected LOGIN response: $response"); return 0; } } Log("Logged in as $user") if $debug; } # logout # # log out from the host # sub logout { my $conn = shift; undef @response; sendCommand ($conn, "1 LOGOUT"); while ( 1 ) { readResponse ($conn); if ( $response =~ /^1 OK/i ) { last; } elsif ( $response !~ /^\*/ ) { Log ("unexpected LOGOUT response: $response"); last; } } close $conn; return; } # getMailboxList # # get a list of the user's mailboxes from the source host # sub getMailboxList { my $conn = shift; my @mbxs; my @mailboxes; # Get a list of the user's mailboxes # if ( $mbxList ) { # The user has supplied a list of mailboxes so only processes # the ones in that list @mbxs = split(/,/, $mbxList); foreach $mbx ( @mbxs ) { trim( *mbx ); push( @mailboxes, $mbx ); } return @mailboxes; } Log("Get list of mailboxes") if $verbose; sendCommand ($conn, "1 LIST \"\" *"); undef @response; while ( 1 ) { readResponse ($conn); if ( $response =~ /^1 OK/i ) { last; } elsif ( $response !~ /^\*/ ) { Log ("unexpected response: $response"); return 0; } } @mbxs = (); for $i (0 .. $#response) { $response[$i] =~ s/\s+/ /; if ( $response[$i] =~ /"$/ ) { $response[$i] =~ /\* LIST \((.*)\) "(.+)" "(.+)"/i; $mbx = $3; } elsif ( $response[$i] =~ /\* LIST \((.*)\) NIL (.+)/i ) { $mbx = $2; } else { $response[$i] =~ /\* LIST \((.*)\) "(.+)" (.+)/i; $mbx = $3; } $mbx =~ s/^\s+//; $mbx =~ s/\s+$//; if ($response[$i] =~ /NOSELECT/i) { Log("$mbx is set NOSELECT,skipping it") if $verbose; next; } if ($mbx =~ /^\#/) { # Skip public mbxs next; } push ( @mbxs, $mbx ) if $mbx ne ''; } return @mbxs; } # getMsgList # # Get a list of the user's messages in the indicated mailbox on # the source host # sub getMsgList { my $mailbox = shift; my $msgs = shift; my $conn = shift; my $seen; my $empty; my $msgnum; my $from; my $flags; # Get a list of the msgs in this mailbox @$msgs = (); trim( *mailbox ); sendCommand ($conn, "1 EXAMINE \"$mailbox\""); undef @response; $empty=0; while ( 1 ) { readResponse ( $conn ); if ( $response =~ / 0 EXISTS/i ) { $empty=1; } if ( $response =~ /^1 OK/i ) { # print STDERR "response $response\n"; last; } elsif ( $response !~ /^\*/ ) { Log ("unexpected response: $response"); # print STDERR "Error: $response\n"; return 0; } } return if $empty; sendCommand ( $conn, "1 FETCH 1:* (uid flags internaldate body[header.fields (From Date Message-ID Subject)])"); undef @response; while ( 1 ) { readResponse ( $conn ); if ( $response =~ /^1 OK/i ) { # print STDERR "response $response\n"; last; } last if $response =~ /^1 NO|^1 BAD/; } @$msgs = (); $flags = ''; for $i (0 .. $#response) { last if $response[$i] =~ /^1 OK FETCH complete/i; if ( $response[$i] =~ /^From: (.+)/ ) { $from = $1; } if ($response[$i] =~ /FLAGS/) { # Get the list of flags $response[$i] =~ /FLAGS \(([^\)]*)/; $flags = $1; $flags =~ s/\\Recent//; } if ( $response[$i] =~ /^Message-ID:\s*\<(.+)\>/i ) { $msgid = $1; } if ( $response[$i] =~ /INTERNALDATE/) { $response[$i] =~ /INTERNALDATE (.+) BODY/i; $date = $1; $date =~ /"(.+)"/; $date = $1; $date =~ s/"//g; } # if ( $response[$i] =~ /\* (.+) [^FETCH]/ ) { if ( $response[$i] =~ /\* (.+) FETCH/ ) { ($msgnum) = split(/\s+/, $1); } if ( $msgnum and $from and $date and $msgid ) { push (@$msgs,"$msgid||||||$msgnum||||||$flags||||||$date"); $msgnum=$from=$msgid=$date=$flags=''; } } } sub createMbx { my $mbx = shift; my $conn = shift; my $created; # Create the mailbox if necessary sendCommand ($conn, "1 CREATE \"$mbx\""); while ( 1 ) { readResponse ($conn); if ( $response =~ /^1 OK/i ) { $created = 1; last; } last if $response =~ /already exists/i; if ( $response =~ /^1 NO|^1 BAD/ ) { Log ("Error creating $mbx: $response"); last; } } Log("Created mailbox $mbx") if $created; } sub fetchMsg { my $msgnum = shift; my $conn = shift; my $message; sendCommand( $conn, "1 FETCH $msgnum (rfc822)"); while (1) { readResponse ($conn); if ( $response =~ /^1 OK/i ) { $size = length($message); last; } elsif ($response =~ /message number out of range/i) { Log ("Error fetching uid $uid: out of range",2); $stat=0; last; } elsif ($response =~ /Bogus sequence in FETCH/i) { Log ("Error fetching uid $uid: Bogus sequence in FETCH",2); $stat=0; last; } elsif ( $response =~ /message could not be processed/i ) { Log("Message could not be processed, skipping it ($user,msgnum $msgnum,$dstMbx)"); push(@errors,"Message could not be processed, skipping it ($user,msgnum $msgnum,$dstMbx)"); $stat=0; last; } elsif ($response =~ /^\*\s+$msgnum\s+FETCH\s+\(.*RFC822\s+\{[0-9]+\}/i) { ($len) = ($response =~ /^\*\s+$msgnum\s+FETCH\s+\(.*RFC822\s+\{([0-9]+)\}/i); $cc = 0; $message = ""; while ( $cc < $len ) { $n = 0; $n = read ($conn, $segment, $len - $cc); if ( $n == 0 ) { Log ("unable to read $len bytes"); return 0; } $message .= $segment; $cc += $n; } } } return $message; } sub fetchMsgFlags { my $msgnum = shift; my $conn = shift; my $flags; # Read the IMAP flags for a message sendCommand( $conn, "1 FETCH $msgnum (flags)"); while (1) { readResponse ($conn); if ( $response =~ /^1 OK|^1 BAD|^1 NO/i ) { last; } if ( $response =~ /\* $msgnum FETCH \(FLAGS \((.+)\)\)/i ) { $flags = $1; Log(" $msgnum - flags $flags") if $verbose; } } return $flags; } sub usage { print STDOUT "usage:\n"; print STDOUT " imapsync -S sourceHost/sourceUser/sourcePassword\n"; print STDOUT " -D destHost/destUser/destPassword\n"; print STDOUT " -d debug\n"; print STDOUT " -L logfile\n"; print STDOUT " -m mailbox list (eg \"Inbox, Drafts, Notes\". Default is all mailboxes)\n"; exit; } sub processArgs { if ( !getopts( "dvS:D:L:m:hIx:y:" ) ) { usage(); } ($sourceHost,$sourceUser,$sourcePwd) = split(/\//, $opt_S); ($destHost, $destUser, $destPwd) = split(/\//, $opt_D); $mbxList = $opt_m; $logfile = $opt_L; $debug = 1 if $opt_d; $verbose = 1 if $opt_v; $showIMAP = 1 if $opt_I; usage() if $opt_h; } sub findMsg { my $msgid = shift; my $conn = shift; my $msgnum; # Search a mailbox on the server for a message by its msgid. Log(" Search for $msgid") if $verbose; sendCommand ( $conn, "1 SEARCH header Message-Id \"$msgid\""); while (1) { readResponse ($conn); if ( $response =~ /\* SEARCH /i ) { ($dmy, $msgnum) = split(/\* SEARCH /i, $response); ($msgnum) = split(/ /, $msgnum); } last if $response =~ /^1 OK|^1 NO|^1 BAD/; last if $response =~ /complete/i; } return $msgnum; } sub deleteMsg { my $conn = shift; my $msgnum = shift; my $rc; # Mark a message for deletion by setting \Deleted flag Log(" msgnum is $msgnum") if $verbose; sendCommand ( $conn, "1 STORE $msgnum +FLAGS (\\Deleted)"); while (1) { readResponse ($conn); if ( $response =~ /^1 OK/i ) { $rc = 1; Log(" Marked $msgid for delete") if $verbose; last; } if ( $response =~ /^1 BAD|^1 NO/i ) { Log("Error setting \Deleted flag for msg $msgnum: $response"); $rc = 0; last; } } return $rc; } sub expungeMbx { my $conn = shift; my $mbx = shift; my $status; # Remove the messages from a mailbox Log("Expunging $mbx mailbox"); sendCommand ( $conn, "1 SELECT \"$mbx\""); while (1) { readResponse ($conn); if ( $response =~ /^1 OK/ ) { $status = 1; last; } if ( $response =~ /^1 NO|^1 BAD/i ) { Log("Error selecting mailbox $mbx: $response"); last; } } return unless $status; sendCommand ( $conn, "1 EXPUNGE"); while (1) { readResponse ($conn); last if $response =~ /^1 OK/; if ( $response =~ /^1 BAD|^1 NO/i ) { print "Error expunging messages: $response\n"; last; } } } sub check_for_adds { my $source_mbxs = shift; my $src = shift; my $dst = shift; my @sourceMsgs; # Compare the contents of the user's mailboxes on the source # with those on the destination. Add any new messages to the # destination and update if necessary the flags on the existing # ones. Log("Checking for adds & updates"); my $added=$updated=0; foreach my $src_mbx ( @$source_mbxs ) { Log("$src_mbx"); expungeMbx( $src, $src_mbx ); $dst_mbx = mailboxName( $src_mbx,$srcPrefix,$srcDelim,$dstPrefix,$dstDelim ); selectMbx( $dst_mbx, $dst, 'SELECT' ); getMsgList( $src_mbx, \@sourceMsgs, $src ); my $msgcount = $#sourceMsgs + 1; Log(" $src_mbx has $msgcount messages"); foreach $_ ( @sourceMsgs ) { ($msgid,$msgnum,$src_flags,$date) = split(/\|\|\|\|\|\|/, $_,5); next if $src_flags =~ /\\Deleted/; # Don't sync deleted messages Log("Searching in $dst_mbx for $msgid") if $verbose; my $dst_msgnum = findMsg( $msgid, $dst ); if ( !$dst_msgnum ) { # The msg doesn't exist in the mailbox on the dst, need to add it. $message = fetchMsg( $msgnum, $src ); Log(" Need to insert $msgnum") if $verbose; insertMsg( $dst, $dst_mbx, *message, $src_flags, $date ); $added++; } else { # The message exists, see if the flags have changed. Log(" msgnum=$msgnum exists, fetch its flags") if $verbose; $dst_flags = fetchMsgFlags( $dst_msgnum, $dst ); sort_flags( \$src_flags ); sort_flags( \$dst_flags ); unless ( $dst_flags eq $src_flags ) { Log(" Updating the flags") if $verbose; setFlags( $dst_msgnum, $src_flags, $dst_flags, $dst ); $updated++; } } } } return ($added,$updated); } sub check_for_deletes { my $dst = shift; my $src = shift; my $deleted; my $total_deletes=0; # Delete any messages on the dst that are no longer on the src. Log("Checking for messages to delete on the dst"); my @dst_mbxs = getMailboxList( $dst ); foreach my $dst_mbx ( @dst_mbxs ) { $deleted=0; $src_mbx = mailboxName( $dst_mbx,$dstPrefix,$dstDelim,$srcPrefix,$srcDelim ); getMsgList( $dst_mbx, \@dstMsgs, $dst ); selectMbx( $dst_mbx, $dst, 'SELECT' ); selectMbx( $src_mbx, $src, 'EXAMINE' ); foreach $_ ( @dstMsgs ) { ($msgid,$dst_msgnum,$dst_flags,$date) = split(/\|\|\|\|\|\|/, $_,5); if ( $verbose ) { Log(" msgid $msgid"); Log(" dst msgnum $dst_msgnum"); Log(" dst_mbx $dst_mbx"); } my $src_msgnum = findMsg( $msgid, $src ); if ( !$src_msgnum ) { Log(" Need to remove $msgid from dst") if $verbose; if ( deleteMsg( $dst, $dst_msgnum ) ) { # Need to expunge messages from this mailbox when we're done $total_deletes++; $deleted=1; } } } expungeMbx( $dst, $dst_mbx ) if $deleted; } return $total_deletes; } sub namespace { my $conn = shift; my $prefix = shift; my $delimiter = shift; my $mbx_delim = shift; # Query the server with NAMESPACE so we can determine its # mailbox prefix (if any) and hierachy delimiter. if ( $mbx_delim ) { # The user has supplied a mbx delimiter and optionally a prefix. Log("Using user-supplied mailbox hierarchy delimiter $mbx_delim"); ($$delimiter,$$prefix) = split(/\s+/, $mbx_delim); return; } @response = (); sendCommand( $conn, "1 NAMESPACE"); while ( 1 ) { readResponse( $conn ); if ( $response =~ /^1 OK/i ) { last; } elsif ( $response =~ /NO|BAD/i ) { Log("Unexpected response to NAMESPACE command: $response"); last; } } foreach $_ ( @response ) { if ( /NAMESPACE/i ) { my $i = index( $_, '((' ); my $j = index( $_, '))' ); my $val = substr($_,$i+2,$j-$i-3); ($val) = split(/\)/, $val); ($$prefix,$$delimiter) = split( / /, $val ); $$prefix =~ s/"//g; $$delimiter =~ s/"//g; last; } last if /^NO|^BAD/; } if ( $verbose ) { Log("prefix $$prefix"); Log("delim $$delimiter"); } } sub mailboxName { my $srcmbx = shift; my $srcPrefix = shift; my $srcDelim = shift; my $dstPrefix = shift; my $dstDelim = shift; my $dstmbx; # Adjust the mailbox name if the source and destination server # have different mailbox prefixes or hierarchy delimiters. $dstmbx = $srcmbx; if ( $srcDelim ne $dstDelim ) { # Need to substitute the dst's hierarchy delimiter for the src's one $srcDelim = '\\' . $srcDelim if $srcDelim eq '.'; $dstDelim = "\\" . $dstDelim if $dstDelim eq '.'; $dstmbx =~ s#$srcDelim#$dstDelim#g; $dstmbx =~ s/\\//g; } if ( $srcPrefix ne $dstPrefix ) { # Replace the source prefix with the dest prefix $dstmbx =~ s#^$srcPrefix## if $srcPrefix; if ( $dstPrefix ) { $dstmbx = "$dstPrefix$dstmbx" unless uc($srcmbx) eq 'INBOX'; } $dstmbx =~ s#^$dstDelim##; } return $dstmbx; } sub flags { my $flags = shift; my @newflags; my $newflags; # Make sure the flags list contains only standard # IMAP flags. return unless $flags; $flags =~ s/\\Recent//i; foreach $_ ( split(/\s+/, $flags) ) { next unless substr($_,0,1) eq '\\'; push( @newflags, $_ ); } $newflags = join( ' ', @newflags ); $newflags =~ s/\\Deleted//ig if $opt_r; $newflags =~ s/^\s+|\s+$//g; return $newflags; } sub createDstMbxs { my $mbxs = shift; my $dst = shift; # Create a corresponding mailbox on the dst for each one # on the src. foreach my $mbx ( @$mbxs ) { $dstmbx = mailboxName( $mbx,$srcPrefix,$srcDelim,$dstPrefix,$dstDelim ); createMbx( $dstmbx, $dst ) unless mbxExists( $dstmbx, $dst ); } } sub mbxExists { my $mbx = shift; my $conn = shift; my $status = 1; # Determine whether a mailbox exists sendCommand ($conn, "1 SELECT \"$mbx\""); while (1) { readResponse ($conn); last if $response =~ /^1 OK/i; if ( $response =~ /^1 NO|^1 BAD/ ) { $status = 0; last; } } return $status; } sub sort_flags { my $flags = shift; my @newflags; my $newflags; # Make sure the flags list contains only standard # IMAP flags. Sort the list to make comparision # easier. return unless $$flags; $$flags =~ s/\\Recent//i; foreach $_ ( split(/\s+/, $$flags) ) { next unless substr($_,0,1) eq '\\'; push( @newflags, $_ ); } @newflags = sort @newflags; $newflags = join( ' ', @newflags ); $newflags =~ s/^\s+|\s+$//g; $$flags = $newflags; } sub setFlags { my $msgnum = shift; my $new_flags = shift; my $old_flags = shift; my $conn = shift; my $rc; # Set the message flags as indicated. if ( $verbose ) { Log("old flags $old_flags"); Log("new flags $new_flags"); } # Clear the old flags sendCommand ( $conn, "1 STORE $msgnum -FLAGS ($old_flags)"); while (1) { readResponse ($conn); if ( $response =~ /^1 OK/i ) { $rc = 1; last; } if ( $response =~ /^1 BAD|^1 NO/i ) { Log("Error setting flags for msg $msgnum: $response"); $rc = 0; last; } } # Set the new flags sendCommand ( $conn, "1 STORE $msgnum +FLAGS ($new_flags)"); while (1) { readResponse ($conn); if ( $response =~ /^1 OK/i ) { $rc = 1; last; } if ( $response =~ /^1 BAD|^1 NO/i ) { Log("Error setting flags for msg $msgnum: $response"); $rc = 0; last; } } } sub selectMbx { my $mbx = shift; my $conn = shift; my $type = shift; my $status; # Select the mailbox. Type is either SELECT (R/W) or EXAMINE (R). sendCommand( $conn, "1 $type \"$mbx\""); while ( 1 ) { readResponse( $conn ); if ( $response =~ /^1 OK/i ) { $status = 1; last; } elsif ( $response =~ /^1 NO|^1 BAD/i ) { Log("Unexpected response to SELECT/EXAMINE $mbx command: $response"); last; } } return $status; }