Getting the 'from' address from a received email

I am trying to pull the email address indicating who an email address is from, from email that I receive. Then I want to list the 'from' addresses in a separate data file.
How can I code this is Java?

public class ReadEmail {
     String from;
     String to;
     String subject;
     HashMap spam;
     public ReadEmail (String name) {
          String aline;
          int pos;
PrintWriter spam_from;
//PrintWriter ham_from;
          spam = new HashMap();
          try {
spam_from = new PrintWriter(new FileWriter("spam_from.txt"));
BufferedReader fin = new BufferedReader (new FileReader(name));
               while ((aline = fin.readLine()) != null) {
                    if (aline.startsWith("From:")) {
                         pos = aline.indexOf ("From:");
                         from = aline.substring (pos + 6);
                         from = from.trim();
int posat, st, fi;
posat = from.indexOf("@");
char ch;
if(posat != -1) {
// we have an email address
st = posat - 1;
while(st >= 0) {
ch = from.charAt(st);
if((ch >= '0' && ch <= '9') ||
(ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
ch == '.' || ch == '_') {
st--;
else break;
} // end of while
fi = posat + 1;
while(fi < from.length()) {
ch = from.charAt(st);
if((ch >= '0' && ch <= '9') ||
(ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
ch == '.' || ch == '_') {
st++;
else break;
} // end of while
// pull out email address
String email = from.substring(st, fi);
System.out.println(email);
// put it in file
spam_from.println(email);
}// end of if
                         System.out.println (from);
                    if (aline.startsWith("To:")) {
                         pos = aline.indexOf ("To:");
                         to = aline.substring (pos + 3);
                         to = to.trim();
                         System.out.println (to);
                    if (aline.startsWith("Subject:")) {
                         pos = aline.indexOf ("Subject:");
                         subject = aline.substring (pos + 8);
                         subject = subject.trim();
                         System.out.println (subject);
          fin.close();
spam_from.close();
     catch (Exception ex) {
          System.out.println (ex.getMessage());
This code alrady:
Pull Headers out:
-�From� ( I want to only accept incoming mail from those addresses present in the address book.)
-�To� (incoming emails which have been sent to multiple users will be rejected.
-�Subject�
Pull Body out:
-Break up string into pieces (a tokeniser does this)
-Individual words are taken.
-Each word is kept account of in a dictionary.
-If Spam contains a key word, we know it is Spam
-Else; ask dave about line 45 onwards!
-A HashMap is something you can put words in. If the word is already there, increment it, if not, put it in.
-Add up how many times a word is read. When in training mode, we can work out word frequency.
Now I'm trying to pull all the 'from' addresses into a separate data file.
Pls help!

Similar Messages

  • When i receive messages from my partner i get the from and email address and her phone

    when i receive messages from my partner i get the from and email address and her phone

    Hey "AppleTechGenius"...you realize the thread you're posting to is almost two years old, & the OP has not posted since that original post, correct?

  • How can I delete an attachment from a received email but save the message?

    Hi all, how can I delete an attachment from a received email but save the message?*

    Over the years this issue crops up again and again. Here are the cases I know about:
    Case 1 - it simply doesn't work
    I have a message in my inbox with a jpeg of about 300Mb. Select message, choose option "remove attachment" which is not greyed out, and it does not work.
    Case 2 - it works if you save the message first
    I move the message from the inbox to a mail box. Open the mailbox (select), select the message, choose option "remove attachment", result: the attachment is removed, a small text file is added and an error appears in the message "missing plug-in". The message size is reduced from 300Mb to a few bytes.
    Case 3 - the option "remove attachment" is greyed out.
    I've googled this at least 10 times and read all the advice about editing various files from the library and all the other hacks. The simple truth here is that the user should not be inconvenienced by such inappropriate behaviour. We're not used to this from Apple any more, not since OS X. Even Windows does this stuff painlessly. In fact this kind of function is something that Outlook and Exchange do incredibly well. If they didn't the corporate world would have ground to a halt.
    My point: the remove attachment option should work all the time and should be redesigned. Right-click + save as + delete in the message would be a hundred times easier.

  • How do I get the MAC address from my iPad?Thanksss.

    How do I get the MAC address from my iPad?Thanksss.

    Settings -> General -> About -> Wi-Fi Address
    Regards.

  • HT4993 I just installed my email accounts and I can receive, but I can't send.  I get the message "address rejected by the server."

    Hello,
    Just got my first iPhone, (the 4s and installed my email accounts, but wonder if I've done something wrong.  I have verified all incoming and outgoing servers, user names and passwords and they are all correct, but while I can receive email, I can't seem to send.  I keep getting the message "address rejected by server."  Can anyone help?  Thank you all for your time...

    You have to go through the out-going server entries again. Consult with your e-mail provider.

  • Trying to setup wifi, how do I get the mac address from ipod touch 5th gen?

    trying to setup wifi, how do I get the mac address from ipod touch 5th gen?  cannot get to the setting screen as it is trying to connect to itunes.

    If yo are setting up the iPod vai wifi you have to connect to a network that does not use MAC address filtering.
    After it is set up yu can get the MAC from Settings>General>About>WiFi Address

  • How to get the Ip address of machine from which a connection is obtained

    Hi,
    We are using Oracle HA solution and we would use at least 2 Db servers. I would like to know whether there is any way of obtaining the Ip address of the machine from which the connection has been obtained?
    Thanks
    Himadri

    know whether
    there is any way of obtaining the Ip address ofthe
    machine from which the connection has beenobtained?
    Let me get you right. Basically looks like you want
    to get the IP address of the client machines who
    connect to your server? Yes it very much possible.
    Even a simple tool like netstat -a -n display
    the IP addresses/port of remote hosts (clients). Its
    part of the IP protocol to carry the addresses in the
    packets. The question is how do you want to do this
    in java? You should look at
    java.net.ServerSocket.accept().getInetAddress()
    API
    trust it helps,
    -BJNo. I have multiple databases which are used in a Oracle RAC solution. You can obtain connections from more than one DB servers. My question was how to obtain get the IP address of the DB Server from which the connection has been obtained.
    Himadri

  • How to get the service address from service address number

    Hi, IS-U Gurus:
    I got the service address number by passing business partner number to  BAPI 'BAPI_ISUPARTNER_GETDETAIL'
    On return table of "bapiisubpa", the first field is service number, but what we need is service address,
    How can I get the service address from service number ?
    Thanks in advance.
    Liang
    Edited by: Liang Ji on Apr 27, 2009 6:57 PM

    hi
    are u looking for business partner address?
    if so u can ref table but020, get its bp no. and then refer table but000 for its address.
    Regards,
    Sumedha

  • Whenever I update my iPhone software, it asks me to sign in to iCloud with an old email address.  My other devices all have the correct address.  How can I get the correct address for my iPhone?  The only Apple ID that works for logging in is my new one.

    Whenever I update my iPhone software, it asks me to sign in to iCloud with an old email address.  My other devices all have the correct address.  How can I get the correct address for my iPhone?  The only Apple ID that works for logging in is my new one.

    To change the iCloud ID you have to go to Settings>iCloud, tap Delete Account, provide the password for the old ID when prompted to turn off Find My iPhone (if you're using iOS 7), then sign back in with the ID you wish to use.  If you don't know the password for your old ID, or if it isn't accepted, go to https//appleid.apple.com, click Manage my Apple ID and sign in with your current iCloud ID.  Tap edit next to the primary email account, tap Edit, change it back to your old email address and save the change.  Then edit the name of the account to change it back to your old email address.  You can now use your current password to turn off Find My iPhone on your device, even though it prompts you for the password for your old account ID. Then go to Settings>iCloud, tap Delete Account and choose Delete from My iDevice when prompted (your iCloud data will still be in iCloud).  Next, go back to https//appleid.apple.com and change your primary email address and iCloud ID name back to the way it was.  Now you can go to Settings>iCloud and sign in with your current iCloud ID and password.

  • When I attempt to connect to iCloud I get the error message: Apple id's email address cannot be verified.  There is nothing wrong with my apple id and I do not want to change it.Any suggestions?

    When I attempt to connect to iCloud I get the error message: Apple id's email address cannot be verified.  There is nothing wrong with my apple id and I do not want to change it.Any suggestions?

    Debi....
    Try "resetting" your Apple ID password >  Apple - My Apple

  • I cannot send emails. i get the sender address was rejected by the server

    i cannot send emails. i get the sender address was rejected by the server

    Greetings.
    Same issue...... can't determine what username and password are ?
    But, went thru process @ apple.com/support and changed port to 25.  :::::
    "Relaying denied" or "Email address rejected by the server" when you try to send email
    This error indicates that either an email address is incorrect or your settings aren't correct for your current connection. Make sure the email address is correct for messages in the Outbox or try a different port:
    If you're on a Wi-Fi network connected to the same network as your email domain, such as your Cable or DSL provider, try port 25:
    Tap Settings > Mail, Contacts, Calendars.
    Tap your email account, then tap Account.
    Scroll down and tap Outgoing Mail Server.
    Tap Primary Server, then tap Server Port.
    Delete the current port and enter 25.
    Tap Done.
    Now my iPhone5s is frozen in the "verifying" mode.  I can not stop it???????????????
    Now what?
    thank you
    cr

  • How to get the MAC address of the additional 10G NIC with ILO command line

    how to get the MAC address of the additional 10G NIC with ILO command line?
    thanks.
    This question was solved.
    View Solution.

    Hi Bruce,
    Out from what I can find on this network card is it not possible to get the mac address without a OS. I would recommend you to get/burn a Linux/Ubuntu live CD/DVD and run a Ifconfig in there.
    Hope it helps you.
    Best regards
    Zincas
    I work on behalf of HP

  • How to get the IP address of printer USB attached to Time Capsule?

    I'm trying to work a printing problem with my HP7310 Officejet and VMware's Fusion 2.0.3. I'm on Mac OS 10.5.5.
    One of the first diagnostic steps for Fusion is to ping the IP address printer. If I open the Print & Fax dialog from System Preferences I can see the name of my printer, let's say it's called "foo bar". I then open a bash terminal and type: ping "foo bar", but get an "unknown host" message.
    I can ping the Time Capsule itself by getting the IP address from Airport Utility. The printer "foo bar" shows properly in the Airport Utility Printers dialog.
    Anyone have any suggestions?

    If you open AirPort Utility > Manual Setup > Advanced > Logs & Statistics > DHCP clients, a list of the devices will be displayed with their IP addresses. Make note of these.
    You will have to get the IP for your printer by process of elimination. Go to
    System Preferences > Network to see your ethernet and wireless connections and associated IPs. You should be able to narrow the list down to identify your printer.

  • How to get the MAC address of a PXI in a dll

    Hi,
    I am looking for a way to get the MAC address of a PXI RT controller. I know that there is a VI to do this, but I am looking for a solution for a dll (C-Code).
    I use the "Call library node" to call this dll and want to make sure that it is only used on a specific PXI.
    Since the VI provides the functionality, I am wondering if it is also available to be called from C-Code?
    Thank you,
    Christian
    Solved!
    Go to Solution.

    ChristianEC wrote:
    Hi,
    I am looking for a way to get the MAC address of a PXI RT controller. I know that there is a VI to do this, but I am looking for a solution for a dll (C-Code).
    I use the "Call library node" to call this dll and want to make sure that it is only used on a specific PXI.
    Since the VI provides the functionality, I am wondering if it is also available to be called from C-Code?
    Thank you,
    Christian
    If it is available in LabVIEW it is probably available in CVI, which you could then build into a DLL (if there isn't one available already).
    CLA, LabVIEW Versions 2010-2013

  • How to get the MAC address of  other hosts in local net

    1. Is there any kerner or user function to get the MAC address of other hosts in local net?
    2. ire_route_lookup() can only lookup MAC in routing table(arp -a),Is there any way to enable it to find out all MAC of hosts in the local net?
    Best Regards
    Hann

    ChristianEC wrote:
    Hi,
    I am looking for a way to get the MAC address of a PXI RT controller. I know that there is a VI to do this, but I am looking for a solution for a dll (C-Code).
    I use the "Call library node" to call this dll and want to make sure that it is only used on a specific PXI.
    Since the VI provides the functionality, I am wondering if it is also available to be called from C-Code?
    Thank you,
    Christian
    If it is available in LabVIEW it is probably available in CVI, which you could then build into a DLL (if there isn't one available already).
    CLA, LabVIEW Versions 2010-2013

  • How to get the IP address of smtp server?

    For A record in DNS, we can use Java API InetAddress.getHostAddress() to get the IP address.
    But for mx record, how to get the IPaddress?

    If you know the hostname of the MX record (eg. mail.somehost.com), you can still use the InetAddress.getByName(hostname).getAddress()
    If you don't know the specific host name you can do a DNS lookup directly:
            String host="somehost.com";
            DirContext ictx = new InitialDirContext();
            Attributes attrs = ictx.getAttributes("dns:/" + host, new String[]{"MX"});This will give you a javax.naming.directory.Attributes object from which you can...
    Attribute att = attrs.get ("MX");This will give you all the MX records for the domain. To get the IP address of the MX hosts, you need to parse the record String returned. Usually something like:
    somehost.com       MX preference = 10, mail exchanger = mail.somehost.comParse out the mail.somehost.com and use:
        String mailhost = <Parse MX record here>
        InetAddress host = InetAddress.getByName(mailhost);

Maybe you are looking for

  • Synching between ipod and itumes

    So I have a bunch of music on my ipod and a bunch on my computer. I want to synch the two so they both have the same music. Everytime I tell itunes to synch the two it comes up with a warning that if I proceed it will erase all the music no the ipod

  • How do i get a download that was interupted and will not resume?

    I tried downloading an album and was told to find a wifi connection due to the last two items size requiring it.  i found the wifi only to find out my iphone no longer connects to wifi.  i plugged it in to my laptop to resume the download, but no luc

  • Upgrading 8.1.7.0 to 10g lastest release (10.2.x)

    I am planning to upgrade a 8.1.7.0 database to 10g r2. I am choosing the export/import method as I cannot seem to find patches that work to upgrade the 8.1.7.0 to 8.1.7.4 in order to perform the manual step-by-step process which does not support vers

  • Multiple front panels

    My problem VI consists of a Main UI where the operator can initiate tests. The tests are sub-vi's and I only need one of those active at a time.  However, there are some general routines that I have together in another sub-vi called from the Main UI.

  • I would like to change my rescure email adress

    I