+#
+# Upgrade legacy version of %UserEmailInfo
+#
+# Prior to 3.2.0, it was a hash with entries:
+#
+# $UserEmailInfo{$user}{lastTime}
+# $UserEmailInfo{$user}{lastSubj}
+# $UserEmailInfo{$user}{lastHost}
+#
+# However, if a user had multiple hosts, then an email about one
+# host prevents mail delivery about other hosts. Starting in 3.2.0
+# the hash is:
+#
+# $UserEmailInfo{$user}{$host}{lastTime}
+# $UserEmailInfo{$user}{$host}{lastSubj}
+#
+my $oldFormat = 0;
+foreach my $user ( keys(%UserEmailInfo) ) {
+ if ( defined($UserEmailInfo{$user}{lastTime})
+ && ref($UserEmailInfo{$user}{lastTime}) ne 'HASH' ) {
+ $oldFormat = 1;
+ last;
+ }
+}
+if ( $oldFormat ) {
+ #
+ # Convert to the new format
+ #
+ my %UserEmailInfoOld = %UserEmailInfo;
+ %UserEmailInfo = ();
+ foreach my $user ( keys(%UserEmailInfoOld) ) {
+ next if ( $user eq "" );
+ my $host = $UserEmailInfoOld{$user}{lastHost};
+ next if ( !defined($host) );
+ $UserEmailInfo{$user}{$host}{lastTime} = $UserEmailInfoOld{$user}{lastTime};
+ $UserEmailInfo{$user}{$host}{lastSubj} = $UserEmailInfoOld{$user}{lastSubj};
+ }
+}
+
+#
+# Prune hosts that no longer exist
+#
+foreach my $user ( keys(%UserEmailInfo) ) {
+ foreach my $host ( keys(%{$UserEmailInfo{$user}}) ) {
+ next if ( defined($Hosts->{$host}) );
+ delete($UserEmailInfo{$user}{$host});
+ }
+ next if ( $UserEmailInfo{$user} );
+ delete($UserEmailInfo{$user});
+}
+