Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.36 KB | None | 0 0
  1. public class DATABASE_KAYIT_SERVICE extends Service {
  2. Timer timing;
  3. Handler helper;
  4. int id = 1;
  5. String server, kullanıcı, sifre;
  6. public static String deneme = null;
  7. public static String govde;
  8. public static String tarih;
  9. public static String konu;
  10. public static String connect = null;
  11. public static String ses2;
  12. public static Integer a;
  13.  
  14. @Override
  15. public IBinder onBind(Intent intent) {
  16. return null;
  17. }
  18.  
  19. @Override
  20. public void onCreate() {
  21. // TODO Auto-generated method stub
  22. super.onCreate();
  23. DATABASE_SERVER db = new DATABASE_SERVER(getApplicationContext());
  24. HashMap<String, String> map = db.kullanici_detay(id);
  25.  
  26. String time = map.get("zaman").toString();
  27. a = Integer.parseInt(time);
  28. System.out.println("ZAMAAANNN" + time);
  29. timing = new Timer();
  30. helper = new Handler(Looper.getMainLooper());
  31. timing.scheduleAtFixedRate(new TimerTask() {
  32.  
  33. @Override
  34. public void run() {
  35. callMethod();
  36. }
  37.  
  38. private void callMethod() {
  39. helper.post(new Runnable() {
  40. public void run()
  41.  
  42. {
  43.  
  44. DATABASE_SERVER asd = new DATABASE_SERVER(getApplicationContext());
  45. HashMap<String, String> map = asd.kullanici_detay(id);
  46.  
  47. server = (map.get("mail_server").toString());
  48. kullanıcı = (map.get("kullanici").toString());
  49. sifre = (map.get("sifre").toString());
  50.  
  51. System.out.println(server);
  52. System.out.println(kullanıcı);
  53. System.out.println(sifre);
  54. String host = server;
  55. String mailStoreType = "pop3";
  56. String username = kullanıcı;
  57. String password = sifre;
  58. String s = "açık";
  59.  
  60.  
  61. if (s.equals(map.get("kontrol").toString())) {
  62. Fetching_Mail(host, mailStoreType, username, password);
  63. delete(host, mailStoreType, username, password);
  64. } else {
  65. System.out.println("Otomatik Güncelleme Servisi Kapalıdır");
  66. }
  67. }
  68.  
  69. protected void Fetching_Mail(String pop3Host, String storeType, String user, String password) {
  70.  
  71. try {
  72. Properties properties = new Properties();
  73. properties.put("mail.store.protocol", "pop3");
  74. properties.put("mail.pop3.host", pop3Host);
  75. properties.put("mail.pop3.port", "110");
  76. properties.put("mail.pop3.starttls.enable", "false");
  77. Session emailSession = Session.getDefaultInstance(properties);
  78. Store store = emailSession.getStore("pop3");
  79. store.connect(pop3Host, user, password);
  80. connect = String.valueOf("a");
  81. Folder emailFolder = store.getFolder("INBOX");
  82. emailFolder.open(Folder.READ_ONLY);
  83. BufferedReader reader = new BufferedReader(new InputStreamReader(
  84. System.in));
  85. Message[] messages = emailFolder.getMessages();
  86. System.out.println("messages.length---" + messages.length);
  87. deneme = String.valueOf(messages.length);
  88.  
  89. for (int i = 0; i < messages.length; i++) {
  90. Message message = messages[i];
  91. System.out.println("---------------------------------");
  92. writePart(message);
  93.  
  94. String line = reader.readLine();
  95. if ("YES".equals(line)) {
  96. message.writeTo(System.out);
  97. } else if ("QUIT".equals(line)) {
  98. break;
  99. }
  100. DATABASE_MAIL db = new DATABASE_MAIL(getApplicationContext());
  101. db.mail_ekle(tarih, konu, govde, null);
  102. db.close();
  103.  
  104.  
  105.  
  106. }
  107. emailFolder.close(true);
  108. store.close();
  109. } catch (NoSuchProviderException e) {
  110. e.printStackTrace();
  111. } catch (MessagingException e) {
  112. e.printStackTrace();
  113. } catch (IOException e) {
  114. e.printStackTrace();
  115. } catch (Exception e) {
  116. e.printStackTrace();
  117. }
  118. }
  119.  
  120. public void writePart(Part p) throws Exception {
  121. if (p instanceof Message)
  122. writeEnvelope((Message) p);
  123. System.out.println("----------------------------");
  124. System.out.println("CONTENT-TYPE: " + p.getContentType());
  125.  
  126. if (p.isMimeType("text/plain")) {
  127. System.out.println("This is plain text");
  128. System.out.println("---------------------------");
  129. System.out.println((String) p.getContent());
  130.  
  131. govde = String.valueOf(p.getContent());
  132.  
  133. System.out.println("Mail Veri Tabanına Eklendi");
  134.  
  135. DATABASE_SERVER db = new DATABASE_SERVER(getApplicationContext());
  136. HashMap<String, String> map = db.kullanici_detay(id);
  137. String ses = map.get("ses");
  138. System.out.println("sesssss : " + ses);
  139. ses2 = "açık";
  140. System.out.println("Stringg sesssss : " + ses2);
  141.  
  142. if (ses.equals(ses2)) {
  143. System.out.println("sesssss111 : " + ses);
  144. System.out.println("Stringg sesssss1111 : " + ses2);
  145. /* NotificationManager bildirimyoneticisi = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  146. Notification notification = new Notification(R.mipmap.ic_launcher, "BİLDİRİM", System.currentTimeMillis());
  147. PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplication(),
  148. MainActivity.class), PendingIntent.FLAG_ONE_SHOT);
  149.  
  150. notification.setLatestEventInfo(getApplication(), konu, govde, pendingIntent);
  151. notification.flags = Notification.FLAG_AUTO_CANCEL;
  152. notification.defaults |= Notification.DEFAULT_VIBRATE;
  153. notification.defaults |= Notification.DEFAULT_SOUND;
  154. bildirimyoneticisi.notify((int) System.currentTimeMillis(), notification);
  155. */
  156. Intent resultIntent = new Intent(getApplicationContext(), MainActivity.class);
  157. resultIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
  158. | Intent.FLAG_ACTIVITY_CLEAR_TASK);
  159. PendingIntent piResult = PendingIntent.getActivity(getApplicationContext(),
  160. (int) Calendar.getInstance().getTimeInMillis(), resultIntent, 0);
  161. NotificationCompat.InboxStyle inboxStyle =
  162. new NotificationCompat.InboxStyle();
  163.  
  164. inboxStyle.setBigContentTitle("Bildirimm");
  165. inboxStyle.addLine(konu);
  166. inboxStyle.addLine(konu);
  167. inboxStyle.addLine(konu);
  168. inboxStyle.addLine(konu);
  169. inboxStyle.addLine(konu);
  170. // inboxStyle.setSummaryText(konu);
  171.  
  172. NotificationCompat.Builder mBuilder =
  173. new NotificationCompat.Builder(getApplicationContext())
  174. .setSmallIcon(R.mipmap.ic_launcher)
  175. .setContentTitle("Inbox style notification")
  176. .setContentText("This is test of inbox style notification.")
  177. .setStyle(inboxStyle)
  178. .addAction(R.mipmap.ic_launcher, "show activity", piResult);
  179.  
  180.  
  181. NotificationManager notificationManager =(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
  182. notificationManager.notify(0, mBuilder.build());
  183.  
  184.  
  185. Fetching_Mail.tarih = " ";
  186. } else {
  187. System.out.println("sesssss2222 : " + ses);
  188. System.out.println("Stringg sesssss2222 : " + ses2);
  189. NotificationManager bildirimyoneticisi = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  190. Notification notification = new Notification(R.mipmap.ic_launcher, "BİLDİRİM", System.currentTimeMillis());
  191. PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplication(),
  192. MainActivity.class), PendingIntent.FLAG_ONE_SHOT);
  193. notification.setLatestEventInfo(getApplication(), konu, govde, pendingIntent);
  194.  
  195. notification.flags = Notification.FLAG_AUTO_CANCEL;
  196. // notification.defaults |= Notification.DEFAULT_VIBRATE;
  197. // notification.defaults |= Notification.DEFAULT_SOUND;
  198. bildirimyoneticisi.notify((int) System.currentTimeMillis(), notification);
  199. System.out.println("Mail Silinmiştir");
  200. Fetching_Mail.tarih = " ";
  201.  
  202. }
  203. } else if (p.isMimeType("multipart/*")) {
  204. System.out.println("This is a Multipart");
  205. System.out.println("---------------------------");
  206. Multipart mp = (Multipart) p.getContent();
  207. int count = mp.getCount();
  208. for (int i = 0; i < count; i++)
  209. writePart(mp.getBodyPart(i));
  210. } else if (p.isMimeType("message/rfc822")) {
  211. System.out.println("This is a Nested Message");
  212. System.out.println("---------------------------");
  213. writePart((Part) p.getContent());
  214. } else if (p.isMimeType("image/jpeg")) {
  215. System.out.println("--------> image/jpeg");
  216. Object o = p.getContent();
  217. InputStream x = (InputStream) o;
  218. // Construct the required byte array
  219. System.out.println("x.length = " + x.available());
  220. int i = 0;
  221. byte[] bArray = new byte[x.available()];
  222.  
  223. while ((i = (int) ((InputStream) x).available()) > 0) {
  224. int result = (int) (((InputStream) x).read(bArray));
  225. if (result == -1)
  226. break;
  227. }
  228. FileOutputStream f2 = new FileOutputStream("/tmp/image.jpg");
  229. f2.write(bArray);
  230. } else if (p.getContentType().contains("image/")) {
  231. System.out.println("content type" + p.getContentType());
  232. File f = new File("image" + new Date(0).getTime() + ".jpg");
  233. DataOutputStream output = new DataOutputStream(
  234. new BufferedOutputStream(new FileOutputStream(f)));
  235. com.sun.mail.util.BASE64DecoderStream test =
  236. (com.sun.mail.util.BASE64DecoderStream) p
  237. .getContent();
  238. byte[] buffer = new byte[1024];
  239. int bytesRead;
  240. while ((bytesRead = test.read(buffer)) != -1) {
  241. output.write(buffer, 0, bytesRead);
  242. }
  243. } else {
  244. Object o = p.getContent();
  245. if (o instanceof String) {
  246. System.out.println("This is a string");
  247. System.out.println("---------------------------");
  248. System.out.println((String) o);
  249.  
  250. } else if (o instanceof InputStream) {
  251. System.out.println("This is just an input stream");
  252. System.out.println("---------------------------");
  253. InputStream is = (InputStream) o;
  254. is = (InputStream) o;
  255. int c;
  256. while ((c = is.read()) != -1)
  257. System.out.write(c);
  258. } else {
  259. System.out.println("This is an unknown type");
  260. System.out.println("---------------------------");
  261. System.out.println(o.toString());
  262. }
  263. }
  264. }
  265.  
  266. protected void writeEnvelope(Message m) throws Exception {
  267. System.out.println("This is the message envelope");
  268. System.out.println("---------------------------");
  269. Address[] a;
  270.  
  271. if ((a = m.getFrom()) != null) {
  272. for (int j = 0; j < a.length; j++)
  273. System.out.println("FROM: " + a[j].toString());
  274. }
  275. if ((a = m.getRecipients(Message.RecipientType.TO)) != null) {
  276. for (int j = 0; j < a.length; j++)
  277. System.out.println("TO: " + a[j].toString());
  278. }
  279. if (m.getSubject() != null)
  280. System.out.println("SUBJECT: " + m.getSubject());
  281. konu = m.getSubject();
  282. if (m.getSentDate() != null)
  283. System.out.println("DATE: " + m.getSentDate());
  284. SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy",
  285. Locale.ENGLISH);
  286. Date parsedDate = sdf.parse(String.valueOf(m.getSentDate()));
  287. SimpleDateFormat print = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
  288. System.out.println(print.format(parsedDate));
  289. tarih = String.valueOf(print.format(parsedDate));
  290. System.out.println("YENİİ TARİHH" + tarih);
  291. }
  292.  
  293.  
  294. });
  295. }
  296.  
  297. }, 0, a * 1000);
  298. }
  299.  
  300. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement