package com.l7tech.server.transport.email.asynch;

import com.l7tech.common.log.HybridDiagnosticContext;
import com.l7tech.server.transport.email.EmailHandler;
import com.l7tech.server.transport.email.EmailHandlerImpl;
import com.l7tech.server.transport.email.EmailListenerConfig;
import com.l7tech.server.transport.email.EmailListenerRuntimeException;
import jakarta.mail.internet.MimeMessage;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Logger;

public class EmailTask implements Runnable {
   private static final Logger a;
   private final EmailListenerConfig b;
   protected final MimeMessage message;
   private EmailHandler c;
   private boolean d;
   private boolean e;
   private List f;
   private final String g;
   private static final String[] h;

   public EmailTask(EmailListenerConfig var1, MimeMessage var2) {
      this.b = var1;
      this.message = var2;
      this.c = new EmailHandlerImpl(var1.getApplicationContext());
      this.f = new ArrayList();
      this.g = h[1];
   }

   // $VF: Could not verify finally blocks. A semaphore variable has been added to preserve control flow.
   // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
   @Override
   public final void run() {
      boolean var6 = false /* VF: Semaphore variable */;

      label74: {
         try {
            var6 = true;
            this.handleMessage();
            var6 = false;
            break label74;
         } catch (EmailListenerRuntimeException var8) {
            a.info(h[4] + var8);
            var6 = false;
         } finally {
            if (var6) {
               try {
                  if (this.f.isEmpty()) {
                     this.e = true;
                  }
               } catch (EmailListenerRuntimeException var7) {
                  throw a(var7);
               }

               this.d = true;
               this.a();
            }
         }

         if (this.f.isEmpty()) {
            this.e = true;
         }

         this.d = true;
         this.a();
         return;
      }

      if (this.f.isEmpty()) {
         this.e = true;
      }

      this.d = true;
      this.a();
   }

   // $VF: Could not verify finally blocks. A semaphore variable has been added to preserve control flow.
   // Please report this to the Vineflower issue tracker, at https://github.com/Vineflower/vineflower/issues with a copy of the class file (if you have the rights to distribute it!)
   protected void handleMessage() throws EmailListenerRuntimeException {
      String[] var2 = h;
      HybridDiagnosticContext.put(var2[3], this.b.getEmailListener().getGoid().toString());
      HybridDiagnosticContext.put(var2[2], this.b.getEmailListener().getName());
      boolean var4 = false /* VF: Semaphore variable */;

      try {
         var4 = true;
         this.c.onMessage(this.b, this.message);
         var4 = false;
      } finally {
         if (var4) {
            var2 = h;
            HybridDiagnosticContext.remove(var2[0]);
            HybridDiagnosticContext.remove(var2[5]);
         }
      }

      HybridDiagnosticContext.remove(var2[0]);
      HybridDiagnosticContext.remove(var2[5]);
   }

   private void a() {
      this.c = null;
   }

   static {
      String[] var5 = new String[6];
      int var3 = 0;
      String var2 = "gor_HC4kqgSJ\u000b*/kw\rvmqST\u0001(wnrBA\n\u000egor_HC4kqgSJ\u000b*\u0011gor_HC4kqgSJ\u000b*/kw";
      int var4 = "gor_HC4kqgSJ\u000b*/kw\rvmqST\u0001(wnrBA\n\u000egor_HC4kqgSJ\u000b*\u0011gor_HC4kqgSJ\u000b*/kw".length();
      char var1 = 17;
      int var7 = -1;

      label24:
      while (true) {
         byte var10000 = 98;
         String var10001 = var2.substring(++var7, var7 + var1);
         byte var10002 = -1;

         while (true) {
            String var8 = a(var10000, a(var10001));
            switch (var10002) {
               case 0:
                  var5[var3++] = var8;
                  if ((var7 += var1) >= var4) {
                     h = var5;
                     a = Logger.getLogger(EmailTask.class.getName());
                     return;
                  }

                  var1 = var2.charAt(var7);
                  break;
               default:
                  var5[var3++] = var8;
                  if ((var7 += var1) < var4) {
                     var1 = var2.charAt(var7);
                     continue label24;
                  }

                  var2 = "\u001d:0\u000f\u0000Npo*&\u0018\fSa& 0[\fMv :0\u000f\fQp+u~\u000e*\"?\u0012\u0005\u000ey&<*\u001e\u0007Fg";
                  var4 = "\u001d:0\u000f\u0000Npo*&\u0018\fSa& 0[\fMv :0\u000f\fQp+u~\u000e*\"?\u0012\u0005\u000ey&<*\u001e\u0007Fg".length();
                  var1 = 31;
                  var7 = -1;
            }

            var10000 = 47;
            var10001 = var2.substring(++var7, var7 + var1);
            var10002 = 0;
         }
      }
   }

   private static EmailListenerRuntimeException a(EmailListenerRuntimeException var0) {
      return var0;
   }

   private static char[] a(String var0) {
      char[] var10000 = var0.toCharArray();
      if (var10000.length < 2) {
         var10000[0] = (char)(var10000[0] ^ 58);
      }

      return var10000;
   }

   private static String a(int var0, char[] var1) {
      int var10003 = var1.length;
      int var10002 = var0;
      char[] var10001 = var1;
      int var10000 = var10003;

      for (int var2 = 0; var10000 > var2; var2++) {
         var10001[var2] = (char)(var10001[var2] ^ var10002 ^ switch (var2 % 7) {
            case 0 -> 96;
            case 1 -> 96;
            case 2 -> 113;
            case 3 -> 84;
            case 4 -> 70;
            case 5 -> 12;
            default -> 58;
         });
      }

      return new String(var10001).intern();
   }
}
