fix бага с отключенной рассылкой
This commit is contained in:
3
.idea/workspace.xml
generated
3
.idea/workspace.xml
generated
@@ -8,7 +8,8 @@
|
|||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
|
<list default="true" id="e42177c3-2328-4b27-8a01-35779b2beb99" name="Default Changelist" comment="">
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/src/TestingSystem/Common/TestingPlanner.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/TestingSystem/Common/TestingPlanner.java" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/src/Repository/RepositoryServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Repository/RepositoryServer.java" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/Repository/Server/ComponentsServer.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Repository/Server/ComponentsServer.java" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
|||||||
@@ -80,7 +80,10 @@ public abstract class RepositoryServer<D extends Database> {
|
|||||||
Log.close();
|
Log.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
protected void checkTargets(EmailMessage message_in) {
|
||||||
|
}
|
||||||
public void Email(EmailMessage message_in, File... directAttachements) throws Exception {
|
public void Email(EmailMessage message_in, File... directAttachements) throws Exception {
|
||||||
|
checkTargets(message_in);
|
||||||
Thread thread = new Thread(() -> {
|
Thread thread = new Thread(() -> {
|
||||||
System.out.println("EMAIL THREAD STARTED");
|
System.out.println("EMAIL THREAD STARTED");
|
||||||
try {
|
try {
|
||||||
@@ -115,49 +118,46 @@ public abstract class RepositoryServer<D extends Database> {
|
|||||||
});
|
});
|
||||||
for (String target : targets_) {
|
for (String target : targets_) {
|
||||||
System.out.println("target=" + target);
|
System.out.println("target=" + target);
|
||||||
if (needsEmail(target)) {
|
boolean done = false;
|
||||||
System.out.println("needs email");
|
int attempts = 5;
|
||||||
boolean done = false;
|
while (!done && (attempts > 0)) {
|
||||||
int attempts = 5;
|
try {
|
||||||
while (!done && (attempts > 0)) {
|
MimeMessage message = new MimeMessage(session);
|
||||||
try {
|
message.setFrom(new InternetAddress(Constants.MailAddress));
|
||||||
MimeMessage message = new MimeMessage(session);
|
message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(target));
|
||||||
message.setFrom(new InternetAddress(Constants.MailAddress));
|
message.setSubject(message_in.subject);
|
||||||
message.setRecipients(Message.RecipientType.CC, InternetAddress.parse(target));
|
Multipart multipart = new MimeMultipart();
|
||||||
message.setSubject(message_in.subject);
|
MimeBodyPart textBodyPart = new MimeBodyPart();
|
||||||
Multipart multipart = new MimeMultipart();
|
textBodyPart.setText(message_in.text);
|
||||||
MimeBodyPart textBodyPart = new MimeBodyPart();
|
multipart.addBodyPart(textBodyPart);
|
||||||
textBodyPart.setText(message_in.text);
|
for (String aName : innerFiles.keySet()) {
|
||||||
multipart.addBodyPart(textBodyPart);
|
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
|
||||||
for (String aName : innerFiles.keySet()) {
|
DataSource source = new FileDataSource(innerFiles.get(aName));
|
||||||
|
attachmentBodyPart.setDataHandler(new DataHandler(source));
|
||||||
|
attachmentBodyPart.setFileName(aName);
|
||||||
|
multipart.addBodyPart(attachmentBodyPart);
|
||||||
|
}
|
||||||
|
for (File f : directAttachements) {
|
||||||
|
if (f.exists()) {
|
||||||
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
|
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
|
||||||
DataSource source = new FileDataSource(innerFiles.get(aName));
|
DataSource source = new FileDataSource(f);
|
||||||
attachmentBodyPart.setDataHandler(new DataHandler(source));
|
attachmentBodyPart.setDataHandler(new DataHandler(source));
|
||||||
attachmentBodyPart.setFileName(aName);
|
attachmentBodyPart.setFileName(f.getName());
|
||||||
multipart.addBodyPart(attachmentBodyPart);
|
multipart.addBodyPart(attachmentBodyPart);
|
||||||
}
|
}
|
||||||
for (File f : directAttachements) {
|
|
||||||
if (f.exists()) {
|
|
||||||
MimeBodyPart attachmentBodyPart = new MimeBodyPart();
|
|
||||||
DataSource source = new FileDataSource(f);
|
|
||||||
attachmentBodyPart.setDataHandler(new DataHandler(source));
|
|
||||||
attachmentBodyPart.setFileName(f.getName());
|
|
||||||
multipart.addBodyPart(attachmentBodyPart);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
message.setContent(multipart);
|
|
||||||
Transport.send(message);
|
|
||||||
System.out.println("message sent");
|
|
||||||
done = true;
|
|
||||||
} catch (Exception ex) {
|
|
||||||
System.out.println("Исключение во время отправки сообщения абоненту " + Utils.Brackets(target));
|
|
||||||
ex.printStackTrace();
|
|
||||||
Utils.sleep(1000);
|
|
||||||
} finally {
|
|
||||||
attempts--;
|
|
||||||
}
|
}
|
||||||
|
message.setContent(multipart);
|
||||||
|
Transport.send(message);
|
||||||
|
System.out.println("message sent");
|
||||||
|
done = true;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
System.out.println("Исключение во время отправки сообщения абоненту " + Utils.Brackets(target));
|
||||||
|
ex.printStackTrace();
|
||||||
|
Utils.sleep(1000);
|
||||||
|
} finally {
|
||||||
|
attempts--;
|
||||||
}
|
}
|
||||||
} else System.out.println("does not need email");
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
System.out.println("Исключение во время выполнения рассылки.");
|
System.out.println("Исключение во время выполнения рассылки.");
|
||||||
@@ -167,9 +167,6 @@ public abstract class RepositoryServer<D extends Database> {
|
|||||||
});
|
});
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
public boolean needsEmail(String email) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
public boolean canDelete(DBObject object) throws Exception {
|
public boolean canDelete(DBObject object) throws Exception {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -322,7 +319,7 @@ public abstract class RepositoryServer<D extends Database> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//--
|
//--
|
||||||
protected Database getDefaultDatabase(){
|
protected Database getDefaultDatabase() {
|
||||||
return db;
|
return db;
|
||||||
}
|
}
|
||||||
//--
|
//--
|
||||||
|
|||||||
@@ -38,6 +38,19 @@ public class ComponentsServer extends RepositoryServer<BugReportsDatabase> {
|
|||||||
return 7995;
|
return 7995;
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
protected void checkTargets(EmailMessage message_in) {
|
||||||
|
Vector<String> checkedTargets = new Vector<>();
|
||||||
|
for (String email: message_in.targets){
|
||||||
|
if (db.subscribers.containsKey(email)){
|
||||||
|
Subscriber subscriber = db.subscribers.get(email);
|
||||||
|
if (subscriber.mailOn>0){
|
||||||
|
checkedTargets.add(email);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
message_in.targets = checkedTargets;
|
||||||
|
}
|
||||||
|
@Override
|
||||||
public void afterDeleteAction(DBObject object) throws Exception {
|
public void afterDeleteAction(DBObject object) throws Exception {
|
||||||
if (object instanceof BugReport) {
|
if (object instanceof BugReport) {
|
||||||
BugReport bugReport = (BugReport) object;
|
BugReport bugReport = (BugReport) object;
|
||||||
|
|||||||
Reference in New Issue
Block a user