validate([ 'context' => ['sometimes', 'in:new,reply,forward,appointment'], 'mailbox' => ['sometimes', 'nullable', 'email:rfc', 'max:254'], ]); $result = $builder->build( $request->attributes->get('directory_user'), $data['context'] ?? 'new', $data['mailbox'] ?? null, ); if ($result === null) { return response()->json(['error' => 'no_template'], 404); } return response()->json($result + ['generated_at' => now()->toIso8601String()]) ->header('Cache-Control', 'private, no-store'); } }