@@ -71,16 +71,17 @@ public function handle()
7171
7272 $ to = $ message ->getTo ()->all ();
7373 $ from = $ message ->getFrom ()->all ();
74- $ cc = $ message ->getCc ()->all ();
75- $ bcc = $ message ->getBcc ()->all ();
76- $ isCyberBuddy = collect ($ to )->contains (self ::SENDER_CYBERBUDDY );
77- $ isMemex = collect ($ to )->contains (self ::SENDER_MEMEX );
74+ $ subject = $ message ->getSubject ()->toString ();
75+ $ isCyberBuddy = collect ($ to )->map (fn (\Webklex \PHPIMAP \Address $ address ) => $ address ->mail )->contains (self ::SENDER_CYBERBUDDY );
76+ $ isMemex = collect ($ to )->map (fn (\Webklex \PHPIMAP \Address $ address ) => $ address ->mail )->contains (self ::SENDER_MEMEX );
7877
7978 if (!$ isCyberBuddy && !$ isMemex ) {
8079 continue ;
8180 }
81+
82+ Log::debug ("From: {$ from [0 ]->mail }\nTo: {$ to [0 ]->mail }\nSubject: {$ subject }" );
83+
8284 if (count ($ from ) !== 1 ) {
83- Log::error ($ message ->getSubject ());
8485 Log::error ('Message from multiple addresses! ' );
8586 continue ;
8687 }
@@ -94,14 +95,13 @@ public function handle()
9495
9596 // Ensure all prompts are properly loaded
9697 /* if (Prompt::count() >= 4) {
97- Log::warning($message->getSubject() );
98+ Log::warning($subject );
9899 Log::warning("Some prompts are not ready yet. Skipping email processing for now.");
99100 continue;
100101 } */
101102
102103 // Ensure all collections are properly loaded
103104 if (File::where ('is_deleted ' , false )->get ()->contains (fn (File $ file ) => !$ file ->is_embedded )) {
104- Log::warning ($ message ->getSubject ());
105105 Log::warning ("Some collections are not ready yet. Skipping email processing for now. " );
106106 } else if ($ isCyberBuddy ) {
107107 $ this ->cyberBuddy ($ user , $ message );
@@ -151,22 +151,22 @@ private function getOrCreateUser(string $email): User
151151 $ this ->importPrompt ($ user , 'default_chat ' , 'seeds/prompts/default_chat.txt ' );
152152 $ this ->importPrompt ($ user , 'default_chat_history ' , 'seeds/prompts/default_chat_history.txt ' );
153153 $ this ->importPrompt ($ user , 'default_debugger ' , 'seeds/prompts/default_debugger.txt ' );
154+ }
154155
155- // Create shadow collections for some frameworks
156- $ frameworks = \App \Models \YnhFramework::all ();
157-
158- foreach ($ frameworks as $ framework ) {
159- if ($ framework ->file === 'seeds/frameworks/anssi/anssi-genai-security-recommendations-1.0.jsonl ' ) {
160- $ this ->importFramework ($ framework , 20 );
161- } else if ($ framework ->file === 'seeds/frameworks/anssi/anssi-guide-hygiene-detail.jsonl ' ) {
162- $ this ->importFramework ($ framework , 10 );
163- } else if ($ framework ->file === 'seeds/frameworks/gdpr/gdpr.jsonl ' ) {
164- $ this ->importFramework ($ framework , 30 );
165- } else if ($ framework ->file === 'seeds/frameworks/dora/dora.jsonl ' ) {
166- $ this ->importFramework ($ framework , 50 );
167- } else if ($ framework ->file === 'seeds/frameworks/nis2/nis2-directive.jsonl ' ) {
168- $ this ->importFramework ($ framework , 40 );
169- }
156+ // Create shadow collections for some frameworks
157+ $ frameworks = \App \Models \YnhFramework::all ();
158+
159+ foreach ($ frameworks as $ framework ) {
160+ if ($ framework ->file === 'seeds/frameworks/anssi/anssi-genai-security-recommendations-1.0.jsonl ' ) {
161+ $ this ->importFramework ($ framework , 20 );
162+ } else if ($ framework ->file === 'seeds/frameworks/anssi/anssi-guide-hygiene-detail.jsonl ' ) {
163+ $ this ->importFramework ($ framework , 10 );
164+ } else if ($ framework ->file === 'seeds/frameworks/gdpr/gdpr.jsonl ' ) {
165+ $ this ->importFramework ($ framework , 30 );
166+ } else if ($ framework ->file === 'seeds/frameworks/dora/dora.jsonl ' ) {
167+ $ this ->importFramework ($ framework , 50 );
168+ } else if ($ framework ->file === 'seeds/frameworks/nis2/nis2-directive.jsonl ' ) {
169+ $ this ->importFramework ($ framework , 40 );
170170 }
171171 }
172172 return $ user ;
@@ -195,7 +195,7 @@ private function importPrompt(User $user, string $name, string $root)
195195 private function importFramework (YnhFramework $ framework , int $ priority ): void
196196 {
197197 $ collection = $ this ->getOrCreateCollection ($ framework ->collectionName (), $ priority );
198- if ($ collection ) {
198+ if ($ collection && $ collection -> files ()-> count () === 0 ) {
199199 $ url = \App \Http \Controllers \CyberBuddyController::saveLocalFile ($ collection , $ framework ->path ());
200200 }
201201 }
@@ -235,8 +235,7 @@ private function cyberBuddy(User $user, \Webklex\PHPIMAP\Message $message): void
235235 // Remove previous messages i.e. rows starting with >
236236 $ body = trim (preg_replace ("/^(>.*)|(On\s+.*\s+wrote:)[ \n\r]?$/im " , '' , $ message ->getTextBody ()));
237237
238- Log::debug ('subject= ' . $ message ->getSubject ()[0 ] ?? '' );
239- Log::debug ('body= ' . $ body );
238+ Log::debug ("body= {$ body }" );
240239
241240 // Call CyberBuddy
242241 $ request = new ConverseRequest ();
@@ -248,7 +247,7 @@ private function cyberBuddy(User $user, \Webklex\PHPIMAP\Message $message): void
248247 $ controller = new CyberBuddyNextGenController ();
249248 $ response = $ controller ->converse ($ request , true );
250249 $ json = json_decode ($ response ->content (), true );
251- $ subject = $ message ->getSubject ()[ 0 ] ?? '' ;
250+ $ subject = $ message ->getSubject ()-> toString () ;
252251 $ body = $ json ['answer ' ]['html ' ] ?? '' ;
253252
254253 EndVulnsScanListener::sendEmail (
@@ -276,14 +275,13 @@ private function cyberBuddy(User $user, \Webklex\PHPIMAP\Message $message): void
276275 );
277276
278277 if (!$ message ->move ('CyberBuddy ' )) {
279- Log::error ($ message ->getSubject ());
280278 Log::error ('Message could not be moved to the CyberBuddy folder! ' );
281279 }
282280 }
283281
284282 private function memex (User $ user , \Webklex \PHPIMAP \Message $ message ): void
285283 {
286- $ item = TimelineItem::createNote ($ user ->id , $ message ->getTextBody (), $ message ->getSubject ()[ 0 ] ?? '' );
284+ $ item = TimelineItem::createNote ($ user ->id , $ message ->getTextBody (), $ message ->getSubject ()-> toString () );
287285 if ($ message ->hasAttachments ()) {
288286 $ collection = $ this ->getOrCreateCollection ("privcol {$ user ->id }" , 0 );
289287 if ($ collection ) {
@@ -300,7 +298,6 @@ private function memex(User $user, \Webklex\PHPIMAP\Message $message): void
300298 }
301299 }
302300 if (!$ message ->move ('Memex ' )) {
303- Log::error ($ message ->getSubject ());
304301 Log::error ('Message could not be moved to the Memex folder! ' );
305302 }
306303 }
0 commit comments