commit 82dbd9c10daefff5d5661aec9bcc8be68cc1ea72 Author: Lukas Martin Date: Mon Nov 28 20:56:37 2022 +0100 [LM] added project to git diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..73f69e0 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..6e411fc --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..de9d2db --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,36 @@ + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..35f4d9b --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,14 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e59dfef --- /dev/null +++ b/pom.xml @@ -0,0 +1,24 @@ + + + 4.0.0 + + org.example + weihnatchswichtelMaven + 1.0-SNAPSHOT + + + 11 + 11 + + + + + com.sun.mail + javax.mail + 1.6.2 + + + + \ No newline at end of file diff --git a/src/main/java/Main.java b/src/main/java/Main.java new file mode 100644 index 0000000..3c7e740 --- /dev/null +++ b/src/main/java/Main.java @@ -0,0 +1,41 @@ + +public class Main { + + public static void main(String[] args) { + String[] people = new String[10]; + String[] mails = new String[10]; + people[0] = "Lukas 0"; + people[1] = "Jan 0"; + people[2] = "Ulrike 0"; + people[3] = "Petra 1"; + people[4] = "Dietmar 1"; + people[5] = "Lisa 1"; + people[6] = "Andreas 1"; + people[7] = "Annette 2"; + people[8] = "Julia 2"; + people[9] = "Mark 2"; + +// mails[0] = "contact@lukasmartin.eu"; +// mails[1] = "janmartin2@hotmail.de"; +// mails[2] = "monsterfamilie@gmx.de"; +// mails[3] = "petra.scheib@t-online.de"; +// mails[4] = "d-scheib@gmx.de"; +// mails[5] = "lisa.scheib92@gmx.de"; +// mails[6] = "andreas_goll@t-online.de"; +// mails[7] = "Annette-simon@t-online.de"; +// mails[8] = "Julia-Marie-simon@gmx.de"; +// mails[9] = "Marcschwarz77@gmail.com"; + + + RandomMatch rm = new RandomMatch(); + SendMail sm = new SendMail(); + String[][] test = rm.match(people); +// for (String[] strings : test) { +// System.out.println(strings[0].substring(0, strings[0].length() - 1) + ": " + strings[1].substring(0, strings[1].length() - 1)); +// } + sm.sendMail(test, mails); + + + + } +} diff --git a/src/main/java/RandomMatch.java b/src/main/java/RandomMatch.java new file mode 100644 index 0000000..edd6c47 --- /dev/null +++ b/src/main/java/RandomMatch.java @@ -0,0 +1,59 @@ +import java.util.Random; + +public class RandomMatch { + + /** + * @author Lukas Martin + * @param people {@code String} + * @info Assigns every person in {@param people} a correct counter part. + */ + public String[][] match(String[] people) { + Random random = new Random(); + int j = 0; + String[][] matches = new String[people.length][people.length]; + for(int i = 0; i < matches.length; i++) { + matches[i][0] = ""; matches[i][1] = ""; + } + for(int i = 0; i < people.length; i++) { + int rand = random.nextInt(10); + if(j > 10000) { + for(int k = 0; k < matches.length; k++) { + matches[k][0] = ""; matches[k][1] = ""; + i = 0; j = 0; + } + } + if(checkRelation(people[i], people[rand]) || isAlreadyDrawn(matches, people[rand])) { + i = i - 1; j = j +1; + } else { + matches[i][0] = people[i]; matches[i][1] = people[rand]; + } + } + return matches; + } + + + /** + * @author Lukas Martin + * @param person0 {@code String} + * @param person1 {@code String} + * @return {@code true} if the two given people are related. + */ + private Boolean checkRelation(String person0, String person1) { + return person0.substring(person0.length() - 1).equals(person1.substring(person1.length() - 1)); + } + + /** + * @author Lukas Martin + * @param matches {@code String[][]} + * @param person {@code String} + * @return {@code true} if person is already drawn. + */ + private Boolean isAlreadyDrawn(String[][] matches, String person) { + for (String[] match : matches) { + if (match[1].equals(person)) { + return true; + } + } + return false; + } +} diff --git a/src/main/java/SendMail.java b/src/main/java/SendMail.java new file mode 100644 index 0000000..72f3b54 --- /dev/null +++ b/src/main/java/SendMail.java @@ -0,0 +1,59 @@ +import javax.mail.*; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import java.util.Properties; + +public class SendMail { + + + /** + * @author Lukas Martin + * @param matches {@code String[][]} + * @param mails {@code String[]} + * @info Uses the params to send mails to the chosen people. + */ + public void sendMail(String[][] matches, String[] mails) { + //authentication info + final String username = "weihnachtswichteln0@gmail.com"; + final String password = "fmrvjhogruskvjkj\n"; + String fromEmail = "weihnachtswichteln0@gmail.com"; + String toEmail = "lukas.martin155@outlook.de"; + + Properties properties = new Properties(); + properties.put("mail.smtp.auth", "true"); + properties.put("mail.smtp.starttls.enable", "true"); + properties.put("mail.smtp.host", "smtp.gmail.com"); + properties.put("mail.smtp.port", "587"); + properties.put("mail.smtp.ssl.trust", "smtp.gmail.com"); + + Session session = Session.getInstance(properties, new javax.mail.Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(username, password); + } + }); + //Start our mail message + for(int i = 0; i < matches.length; i++) { + MimeMessage msg = new MimeMessage(session); + try { + msg.setFrom(new InternetAddress(fromEmail)); + msg.addRecipient(Message.RecipientType.TO, new InternetAddress(mails[i])); + msg.setSubject("Weihnachtswichteln 2023"); + msg.setText("Hallo liebe/r " + matches[i][0].substring(0, matches[i][0].length() - 2)+ "," + "\n" + + "\n" + + "Dein Match für das diesjährige Wichteln ist " + matches[i][1].substring(0, matches[i][1].length() - 2) + "." + "\n" + + "\n" + + "Mit freundlichen Grüßen \n" + + "Dein Wichtelsystem" + "\n" + + "\n" + "\n" + + + "--Bitte beachtet, dass ungefähr für 25€ gewichtelt wird--"); + Transport.send(msg); + } catch (MessagingException e) { + e.printStackTrace(); + } + } + + + + } +} diff --git a/src/main/resources/data.conf b/src/main/resources/data.conf new file mode 100644 index 0000000..8c0727d --- /dev/null +++ b/src/main/resources/data.conf @@ -0,0 +1 @@ +amount: 10 diff --git a/target/classes/Main.class b/target/classes/Main.class new file mode 100644 index 0000000..864de52 Binary files /dev/null and b/target/classes/Main.class differ diff --git a/target/classes/RandomMatch.class b/target/classes/RandomMatch.class new file mode 100644 index 0000000..a3ce48d Binary files /dev/null and b/target/classes/RandomMatch.class differ diff --git a/target/classes/SendMail$1.class b/target/classes/SendMail$1.class new file mode 100644 index 0000000..bc65b5a Binary files /dev/null and b/target/classes/SendMail$1.class differ diff --git a/target/classes/SendMail.class b/target/classes/SendMail.class new file mode 100644 index 0000000..e51f25d Binary files /dev/null and b/target/classes/SendMail.class differ diff --git a/target/classes/data.conf b/target/classes/data.conf new file mode 100644 index 0000000..8c0727d --- /dev/null +++ b/target/classes/data.conf @@ -0,0 +1 @@ +amount: 10 diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 0000000..17df8b4 --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,5 @@ +#Generated by Maven +#Wed Nov 10 19:44:59 CET 2021 +groupId=org.example +artifactId=weihnatchswichtelMaven +version=1.0-SNAPSHOT diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..db04741 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,3 @@ +F:\1_java\weihnatchswichtelMaven\src\main\java\SendMail.java +F:\1_java\weihnatchswichtelMaven\src\main\java\Main.java +F:\1_java\weihnatchswichtelMaven\src\main\java\RandomMatch.java diff --git a/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/testCompile/default-testCompile/inputFiles.lst new file mode 100644 index 0000000..e69de29 diff --git a/target/weihnatchswichtelMaven-1.0-SNAPSHOT.jar b/target/weihnatchswichtelMaven-1.0-SNAPSHOT.jar new file mode 100644 index 0000000..0365688 Binary files /dev/null and b/target/weihnatchswichtelMaven-1.0-SNAPSHOT.jar differ