Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Script läuft weiter trotz anhalten

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Script läuft weiter trotz anhalten

    This topic has been deleted. Only users with topic management privileges can see it.
    • Gargano
      Gargano last edited by Gargano

      Ich habe ein Script um Email mit dem Subject und Namen auf meinem TV als Popup anzuzeigen.
      Wenn ich das Script stoppe , kommen trotzdem noch die Popups auf dem TV.
      Es scheint, als ob

      mailListener.on(... ) 
      

      immer noch aktiv ist.
      Kann einer das erklären und was muß ich tun um das zu stoppen ?
      Vielen Dank

      crunchip 1 Reply Last reply Reply Quote 0
      • crunchip
        crunchip Forum Testing Most Active @Gargano last edited by

        @gargano auch wenn ich mich damit gar nicht auskenne, finde ich es immer wieder witzig, wenn nach Fehlern und Problemen gefragt wird, obwohl man, wie in deinem Fall, das Script gar nicht kennt.
        Nicht böse gemeint😉 , aber ein wenig mehr Info wäre angebracht, als nur ein Einzeiler

        Gargano 1 Reply Last reply Reply Quote 1
        • Gargano
          Gargano @crunchip last edited by

          @crunchip Ich wollte erstmal nicht den ganzen Code einstellen, um den Post kurz zu halten, falls jemand die Antwort kennt..

          Aber hier bitte dann der ganze Code :

          
          
          // Quelle Original: https://github.com/chirag04/mail-listener2
          // Quelle Forum: https://forum.iobroker.net/topic/18501/emails-empfangen
           
          
          const prefix = '0_userdata.0.'; 
          
          const idEmailSubject = prefix + "Email.EmailSubject";
          const idEmailAddress = prefix + "Email.EmailAddress";
          const idEmailName = prefix + "Email.EmailName";
          const idLGTVPopUp = 'lgtv.0.states.popup';
          
          const createStateList = [
              {name :idEmailAddress, type:"string", role : "value"},
              {name :idEmailSubject, type:"string", role : "value"},
              {name :idEmailName, type:"string", role : "value"}
          ]
          
          createStateList.forEach (function(item) {
              createState(item.name, { 
                  type: item.type,
                  min: 0,
                  def: 0,
                  role: item.role
              });
          });
          
          
              var MailListener = require("mail-listener4");
              var mailListener = new MailListener({
                username: "user",    // HIER Email Adresse eintragen
                password: "passwort",	      // HIER Passwort eintragen	
                host: "host",
                port: 993, // imap port
                tls: true,
                connTimeout: 10000, // Default by node-imap
                authTimeout: 5000, // Default by node-imap,
                debug: null, // Or your custom function with only one incoming argument. Default: null
                tlsOptions: { rejectUnauthorized: false },
                mailbox: "INBOX", // HIER Postfach eingeben z.B. INBOX 
                searchFilter: ["UNSEEN"], // the search filter being used after an IDLE notification has been retrieved
                markSeen: false, // all fetched email willbe marked as seen and not fetched next time
                fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`,
                mailParserOptions: {streamAttachments: false}, // options to be passed to mailParser lib.
                attachments: false, // download attachments as they are encountered to the project directory
                attachmentOptions: { directory: "attachments/" } // specify a download directory for attachments
              });
          
              mailListener.start();
              mailListener.on("server:connected", function(){console.log("------- imapConnected");});
              mailListener.on("server:disconnected", function(){console.log("------- imapDisconnected");});
              mailListener.on("error", function(err){console.log("MailError "+err);});
             
              mailListener.on("mail", function(mail, seqno, attributes){
                  setState(idEmailAddress,mail.from[0].address);  	//setze Datenpunkt mit Email-Absender (als Trigger nutzbar)
                  setState(idEmailSubject,mail.subject);			//setze Datenpunkt mit kompletten Email-Inhalt
                  setState(idEmailName,mail.from[0].name);
           
                  setState(idLGTVPopUp,"Email von "+mail.from[0].name +" : "+ mail.subject);
            
              });
          
           
          
          
          
          Asgothian 1 Reply Last reply Reply Quote 0
          • Asgothian
            Asgothian Developer @Gargano last edited by Asgothian

            @gargano
            Damit ist die Antwort auch schon klar:

            Du musst in der Dokumentation des Projektes "mail-listener4" nachsehen. Neben einem "subscribe", der durch die on() Funktionsaufrufe ausgelöst wird müsste es auch ein "unsubscribe" geben. Diesen musst du explizit beim Stop des Skriptes aufrufen, ansonsten bleiben die Subscriptions aktiv.

            Alternativ kann es auch ein "stop()" als Gegenpol zu "start()" geben.

            A.

            Gargano 1 Reply Last reply Reply Quote 0
            • Gargano
              Gargano @Asgothian last edited by

              @asgothian Vielen Dank für die schnelle Antwort😊
              Allerdings : wie mache ich das unsubscribe automatisch, wenn ich das Script stoppe ? Gibt es sowas wie ein Ereignis, welches aufgerufen wird, wenn das Script gestoppt wird ?

              Asgothian 1 Reply Last reply Reply Quote 0
              • Asgothian
                Asgothian Developer @Gargano last edited by

                @gargano

                Siehe Doku JS Adapter:

                https://github.com/ioBroker/ioBroker.javascript/blob/master/docs/en/javascript.md#onstop

                onStop() ist die Funktion die du brauchst.

                Bliebe noch die Frage warum..... den rest spar ich mir.

                A.

                Gargano 1 Reply Last reply Reply Quote 0
                • Gargano
                  Gargano @Asgothian last edited by

                  @asgothian Danke, funktioniert.
                  Ja, warum ?
                  Ich mache eine Meldung auf dem TV wenn eine Email kommt.
                  Da gestern gefühlt 100 Emails kamen, hat sich meine Frau beschwert und in gutem Glauben, daß die Meldungen nicht mehr kommen, habe ich ich das Script gestoppt.
                  Jetzt wollte ich halt wissen, wieso immer noch.

                  Evtl. bleibt nur die Frage : braucht man das ?
                  Was man braucht oder nur haben will, ist jedem selbst überlassen.

                  Asgothian 1 Reply Last reply Reply Quote 0
                  • Asgothian
                    Asgothian Developer @Gargano last edited by

                    @gargano

                    Ich fürchte du hast den Kommentar falsch verstanden. Das Warum ging darum warum Du die Doku zum JS Adapter nicht selber gefunden hast.

                    Da steht alles drin.

                    A.

                    Gargano 1 Reply Last reply Reply Quote 0
                    • Gargano
                      Gargano @Asgothian last edited by

                      @asgothian Ah, ok.
                      Trotzdem Danke für den Hinweis.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post

                      Support us

                      ioBroker
                      Community Adapters
                      Donate

                      895
                      Online

                      31.8k
                      Users

                      80.0k
                      Topics

                      1.3m
                      Posts

                      3
                      9
                      336
                      Loading More Posts
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes
                      Reply
                      • Reply as topic
                      Log in to reply
                      Community
                      Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                      The ioBroker Community 2014-2023
                      logo