Guest User

Untitled

a guest
Apr 20th, 2018
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. public class Main {
  2.  
  3. public static void main(String[] args) throws FileNotFoundException {
  4.  
  5. KeyStoreParameters ksp = new KeyStoreParameters();
  6. ksp.setResource("C://Program Files (x86)//Java//jre1.8.0_161//lib//security");
  7. ksp.setPassword("changeit");
  8.  
  9. KeyManagersParameters kmp = new KeyManagersParameters();
  10. kmp.setKeyStore(ksp);
  11. kmp.setKeyPassword("changeit");
  12.  
  13. SSLContextParameters scp = new SSLContextParameters();
  14. scp.setKeyManagers(kmp);
  15.  
  16.  
  17. BasicConfigurator.configure();
  18. RutaMail routeBuilder = new RutaMail();
  19.  
  20. SimpleRegistry jndi= new SimpleRegistry();
  21. jndi.put("keystore", scp);
  22.  
  23. CamelContext ctx = new DefaultCamelContext(jndi);
  24.  
  25.  
  26.  
  27.  
  28.  
  29. try {
  30.  
  31. ctx.addRoutes(routeBuilder);
  32. ctx.start();
  33. Thread.sleep(30000);
  34. ctx.stop();
  35. } catch (Exception e) {
  36. e.printStackTrace();
  37. }
  38.  
  39. }
  40.  
  41. }
  42.  
  43. public void configure() throws Exception {
  44.  
  45. from("imaps://imap.gmail.com:993?username=user@gmail.com&password=password"
  46. + "&delete=false&unseen=true&consumer.delay=60000&contentType=multipart/MIXED")
  47. .convertBodyTo(String.class, "UTF-8")
  48. .process(new MailProcessor())
  49.  
  50. .to("file:C:/outputFolder/?flatten=true&fileName=${header.nombref}")
  51. .log("el nombre del archivo es ${header.nombref}").end();
  52. }
  53.  
  54. }
  55.  
  56. public class MailProcessor implements Processor {
  57.  
  58. public void process(Exchange exchange) throws Exception {
  59. String nombre="";
  60.  
  61.  
  62. // the API is a bit clunky so we need to loop
  63. Map<String, DataHandler> attachments = exchange.getIn().getAttachments();
  64.  
  65. String file="";
  66.  
  67. if (attachments.size() > 0) {
  68. for (String name : attachments.keySet()) {
  69.  
  70.  
  71. DataHandler dh = attachments.get(name);
  72.  
  73. String filename =dh.getName();
  74. nombre =filename;
  75.  
  76.  
  77. byte[] data = exchange.getContext().getTypeConverter()
  78. .convertTo(byte[].class, dh.getInputStream());
  79.  
  80. exchange.getIn().setBody( data);
  81. exchange.getIn().setHeader("nombref", filename);
  82. }
  83.  
  84.  
  85. }
  86. }
  87.  
  88. }
Add Comment
Please, Sign In to add comment