Magic email transformation! Or: help the NSA extract your metadata from your email address Given an email address, the result of a transformation applied to that email address, and a second email address, return the output of the same transformation applied to the second email address.

The email addresses will all have the following structure:

A string of positive length containing alphanumeric characters and at most one . (the local part), followed by an @ symbol, followed by a string of positive length containing alphanumeric sumbols (the domain), followed by a . symbol, and a final string of positive length containing alphanumeric characters (the TLD).

There are four allowed transformations:


Identity (no change). (a.b@c.d -&gt; a.b@c.d)
Returning just the local part (everything before the @) unmodified (a.b@c.d -&gt; a.b).
Returning the local part split on the . if present, with the first symbol of each half capitalised. (a.b@c.d -&gt; A B).
Returning just the domain (everything between the @ and the final .) unmodified. (a.b@c.d -&gt; c).


When more than one transformation is possible, you can give the output of any of the possibilities. Whitespace at the start and end of output don't matter, but in the middle does (i.e. if you split a.b to A B there should be just one space in the middle [and any number at the start and end of output], but if you split a., then A with any number of spaces on either side are all acceptable).

Examples (input | output):

john.doe@gmail.com, John Doe, phillip.maini@gmail.com         | Phillip Maini
John.Doe@gmail.com, John Doe, Phillip.Maini@gmail.com         | Phillip Maini
foo.bar@hotmail.com, foo.bar, gee.whizz@outlook.com           | gee.whizz
foo.bar@hotmail.com, foo.bar, gEe.Whizz@outlook.com           | gEe.Whizz
rodney.dangerfield@comedy.net, comedy, michael.scott@office.0 | office
.jones@x.1, Jones, a.@3.z                                     | A
.jones@x.1, .jones@x.1, a.@3.z                                | a.@3.z
.jones@x.1, .jones, a.@3.z                                    | a.
.jones@x.1, x, a.@3.z                                         | 3
.@b.c, .@b.c, 1@2.3                                           | 1@2.3
john.jones@f.f, John Jones, 1in.thehand@2inthe.bush           | 1in Thehand
chicken.soup@q.z, Chicken Soup, fab@ulou.s                    | Fab
lange@haare.0, lange, fat.so@fat.net                          | fat.so
Lange@haare.0, Lange, fat.so@fat.net                          | {fat.so, Fat So} # either acceptable
chicken@chicken.chicken, chicken, horse@pig.farm              | {horse, pig} # either acceptable


Usual rules and loopholes apply.
Java 8, 254 240 236 bytes

(a,b,c)-&gt;{String A[]=a.split(&quot;@&quot;),C[]=c.split(&quot;@&quot;),x=&quot;&quot;;for(String p:C[0].split(&quot;\\.&quot;))x+=(p.charAt(0)+&quot;&quot;).toUpperCase()+p.substring(1)+&quot; &quot;;return a.equals(b)?c:A[0].equals(b)?C[0]:A[1].split(&quot;\\.&quot;)[0].equals(b)?C[1].split(&quot;\\.&quot;)[0]:x;}

-4 bytes thanks to @LukeStevens.
Explanation:
Try it here.
(a,b,c)-&gt;{                  // Method with three String parameters and String return-type
  String A[]=a.split(&quot;@&quot;),  //  Split `a` by &quot;@&quot; into two parts
         C[]=c.split(&quot;@&quot;),  //  Split `c` by &quot;@&quot; into two parts
         x=&quot;&quot;;              //  Temp-String
  for(String p:C[0].split(&quot;\\.&quot;)) 
                            //  Loop over the first part of `c`, split by dots
    x+=                     //   Append String `x` with:
       (p.charAt(0)+&quot;&quot;).toUpperCase()
                            //    The first character as uppercase
       +p.substring(1)      //    + the rest of the String
       +&quot; &quot;;                //    + a space
                            //  End of loop (implicit / single-line body)
  return a.equals(b)?       //  If input `a` and `b` are exactly the same:
    c                       //   Return `c`
   :A[0].equals(b)?         //  Else-if the first part of `a` equals `b`:
    C[0]                    //   Return the first part of `c`
   :A[1].split(&quot;\\.)[0].equals(b)?
                            //  Else-if the domain of `a` equals `b`
    C[1].split(&quot;\\.)[0]     //   Return the domain of `c`
   :                        //  Else:
    x;                      //   Return String `x`
}                           // End of method