Guest User

Untitled

a guest
Jul 31st, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.42 KB | None | 0 0
  1. package com.example;
  2.  
  3. import android.app.Activity;
  4. import android.app.AlertDialog;
  5. import android.content.Context;
  6. import android.os.Bundle;
  7. import android.view.View;
  8. import android.widget.Button;
  9. import android.widget.EditText;
  10. import android.widget.Toast;
  11.  
  12. import java.util.Properties;
  13. import javax.activation.DataHandler;
  14. import javax.mail.*;
  15. import javax.mail.search.FlagTerm;
  16.  
  17.  
  18. public class Home extends Activity
  19. {
  20.     Button button;
  21.     /** Called when the activity is first created. */
  22.     @Override
  23.     public void onCreate(Bundle savedInstanceState)
  24.     {
  25.         super.onCreate(savedInstanceState);
  26.         setContentView(R.layout.main);
  27.         addListenerOnButton();
  28.     }
  29.     public void addListenerOnButton() {
  30.         button = (Button) findViewById(R.id.btnGO);
  31.         button.setOnClickListener(new View.OnClickListener() {
  32.             @Override
  33.             public void onClick(View arg0) {
  34.                 EditText UN = (EditText)findViewById(R.id.txtUN);
  35.                 EditText PW = (EditText)findViewById(R.id.txtPW);
  36.                 String  userName = UN.getText().toString();
  37.                 String password = PW.getText().toString();
  38.                 exec(userName,password);
  39.  
  40.                 //To change body of implemented methods use File | Settings | File Templates.
  41.             }
  42.         });
  43.     }
  44.  
  45.     public void exec(String user, String pass){
  46.  
  47.         Properties props = System.getProperties();
  48.         props.setProperty("mail.store.protocol", "imaps");
  49.         try {
  50.             Session session = Session.getDefaultInstance(props, null);
  51.             Store store = session.getStore("imaps");
  52.             store.connect("imap.gmail.com", user, pass);
  53.             //System.out.println(store);
  54.  
  55.             Folder inbox = store.getFolder("Inbox");
  56.             inbox.open(Folder.READ_WRITE);
  57.             int unread = inbox.getUnreadMessageCount();
  58.  
  59.             FlagTerm ft = new FlagTerm(new Flags(Flags.Flag.SEEN), false) ;
  60.             Message messages[] = inbox.search(ft);
  61.  
  62.  
  63.             for(Message message:messages){
  64.                 //System.out.print(newline);
  65.                 message.setFlag(Flags.Flag.SEEN, true);
  66.             }
  67.  
  68.  
  69.  
  70.         } catch (NoSuchProviderException e) {
  71.             e.printStackTrace();
  72.             System.exit(1);
  73.         } catch (MessagingException e) {
  74.             e.printStackTrace();
  75.             System.exit(2);
  76.         }
  77.  
  78.  
  79.  
  80.     }
  81. }
Add Comment
Please, Sign In to add comment