code
stringlengths 15
9.96M
| docstring
stringlengths 1
10.1k
| func_name
stringlengths 1
124
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 6
186
| url
stringlengths 50
236
| license
stringclasses 4
values |
---|---|---|---|---|---|---|---|
public function __invoke(Request $request)
{
return response(
file_get_contents(LaRecipe::allScripts()[$request->script]),
200, ['Content-Type' => 'application/javascript']
);
} | @param Request $request
@return \Illuminate\Contracts\Routing\ResponseFactory|\Illuminate\Http\Response | __invoke | php | saleem-hadad/larecipe | src/Http/Controllers/ScriptController.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Http/Controllers/ScriptController.php | MIT |
public function parse($source)
{
return (new ParsedownExtra)->text($source);
} | Parse the given source to Markdown, using your Markdown parser of choice.
@param string $source Markdown source contents
@return null|string|string[] HTML output | parse | php | saleem-hadad/larecipe | src/Services/ParseDownMarkdownParser.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Services/ParseDownMarkdownParser.php | MIT |
protected static function getFacadeAccessor()
{
return 'LaRecipe';
} | Get the registered name of the component.
@return string | getFacadeAccessor | php | saleem-hadad/larecipe | src/Facades/LaRecipe.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Facades/LaRecipe.php | MIT |
protected function findComposer()
{
if (file_exists(getcwd().'/composer.phar')) {
return '"'.PHP_BINARY.'" '.getcwd().'/composer.phar';
}
return 'composer';
} | Get the composer command for the environment.
@return string | findComposer | php | saleem-hadad/larecipe | src/Commands/InstallCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/InstallCommand.php | MIT |
public function handle()
{
if (! $this->hasValidNameArgument()) {
return;
}
if ($this->option('remove')) {
$this->removeTheme();
$this->info('Successfully removed LaRecipe theme.');
return;
}
(new Filesystem)->copyDirectory(
__DIR__.'/../../stubs/theme-stubs',
$this->themePath()
);
// ThemeServiceProvider.php replacements...
$this->replace('{{ namespace }}', $this->themeNamespace(), $this->themePath().'/src/ThemeServiceProvider.stub');
$this->replace('{{ component }}', $this->themeName(), $this->themePath().'/src/ThemeServiceProvider.stub');
$this->replace('{{ name }}', $this->themeName(), $this->themePath().'/src/ThemeServiceProvider.stub');
// Theme composer.json replacements...
$this->replace('{{ name }}', $this->argument('name'), $this->themePath().'/composer.json');
$this->replace('{{ escapedNamespace }}', $this->escapedThemeNamespace(), $this->themePath().'/composer.json');
// Rename the stubs with the proper file extensions...
$this->renameStubs();
// Register the theme...
$this->addThemeRepositoryToRootComposer();
$this->addThemePackageToRootComposer();
if ($this->confirm('Would you like to update your Composer packages?', true)) {
$this->composerUpdate();
}
} | Execute the console command.
@return void | handle | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
protected function stubsToRename()
{
return [
$this->themePath().'/src/ThemeServiceProvider.stub',
];
} | Get the array of stubs that need PHP file extensions.
@return array | stubsToRename | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
protected function addThemeRepositoryToRootComposer()
{
$composer = json_decode(file_get_contents(base_path('composer.json')), true);
$composer['repositories'][] = [
'type' => 'path',
'url' => './'.$this->relativeThemePath(),
];
file_put_contents(
base_path('composer.json'),
json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
} | Add a path repository for the theme to the application's composer.json file.
@return void | addThemeRepositoryToRootComposer | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
protected function addThemePackageToRootComposer()
{
$composer = json_decode(file_get_contents(base_path('composer.json')), true);
$composer['require'][$this->argument('name')] = '*';
file_put_contents(
base_path('composer.json'),
json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
} | Add a package entry for the theme to the application's composer.json file.
@return void | addThemePackageToRootComposer | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
protected function composerUpdate()
{
$this->runProcess('composer update', getcwd());
} | Update the project's composer dependencies.
@return void | composerUpdate | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
protected function replace($search, $replace, $path)
{
file_put_contents($path, str_replace($search, $replace, file_get_contents($path)));
} | Replace the given string in the given file.
@param string $search
@param string $replace
@param string $path
@return void | replace | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
protected function themePath()
{
return base_path($this->relativeThemePath());
} | Get the path to the theme.
@return string | themePath | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
protected function relativeThemePath()
{
return config('larecipe.packages.path', 'larecipe-components').'/'.$this->themeClass();
} | Get the relative path to the theme.
@return string | relativeThemePath | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
protected function themeNamespace()
{
return Str::studly($this->themeVendor()).'\\'.$this->themeClass();
} | Get the theme's namespace.
@return string | themeNamespace | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
protected function escapedThemeNamespace()
{
return str_replace('\\', '\\\\', $this->themeNamespace());
} | Get the theme's escaped namespace.
@return string | escapedThemeNamespace | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
protected function themeClass()
{
return Str::studly($this->themeName());
} | Get the theme's class name.
@return string | themeClass | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
protected function themeVendor()
{
return explode('/', $this->argument('name'))[0];
} | Get the theme's vendor.
@return string | themeVendor | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
protected function themeName()
{
return explode('/', $this->argument('name'))[1];
} | Get the theme's base name.
@return string | themeName | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
public function hasValidNameArgument()
{
$name = $this->argument('name');
if (! Str::contains($name, '/')) {
$this->error("The name argument expects a vendor and name in 'Composer' format. Here's an example: `vendor/name`.");
return false;
}
return true;
} | Determine if the name argument is valid.
@return bool | hasValidNameArgument | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
protected function removeTheme()
{
$this->runProcess('composer remove '.$this->argument('name'), getcwd());
(new Filesystem)->deleteDirectory($this->themePath());
} | Remove the theme specified by vendor-name/theme
@return void | removeTheme | php | saleem-hadad/larecipe | src/Commands/ThemeCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/ThemeCommand.php | MIT |
public function __construct(Filesystem $filesystem)
{
$this->filesystem = $filesystem;
parent::__construct();
} | Create a new command instance.
@param Filesystem $filesystem | __construct | php | saleem-hadad/larecipe | src/Commands/GenerateDocumentationCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/GenerateDocumentationCommand.php | MIT |
protected function createVersionDirectory($versionDirectory)
{
if (! $this->filesystem->isDirectory($versionDirectory)) {
$this->filesystem->makeDirectory($versionDirectory, 0755, true);
return true;
}
return false;
} | Create a new directory for the given version if not exists.
@return bool | createVersionDirectory | php | saleem-hadad/larecipe | src/Commands/GenerateDocumentationCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/GenerateDocumentationCommand.php | MIT |
protected function createVersionIndex($versionDirectory)
{
$indexPath = $versionDirectory.'/index.md';
if (! $this->filesystem->exists($indexPath)) {
$content = $this->generateIndexContent($this->getStub('index'));
$this->filesystem->put($indexPath, $content);
return true;
}
return false;
} | Create index.md for the given version if it's not exists.
@param $versionDirectory
@return bool
@throws \Illuminate\Contracts\Filesystem\FileNotFoundException | createVersionIndex | php | saleem-hadad/larecipe | src/Commands/GenerateDocumentationCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/GenerateDocumentationCommand.php | MIT |
protected function createVersionLanding($versionDirectory)
{
$landingPath = $versionDirectory.'/'.config('larecipe.docs.landing').'.md';
if (! $this->filesystem->exists($landingPath)) {
$content = $this->generateLandingContent($this->getStub('landing'));
$this->filesystem->put($landingPath, $content);
return true;
}
return false;
} | Create {landing}.md for the given version if it's not exists.
@param $versionDirectory
@return bool
@throws \Illuminate\Contracts\Filesystem\FileNotFoundException | createVersionLanding | php | saleem-hadad/larecipe | src/Commands/GenerateDocumentationCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/GenerateDocumentationCommand.php | MIT |
protected function generateIndexContent($stub)
{
$content = str_replace(
'{{LANDING}}',
ucwords(config('larecipe.docs.landing')),
$stub
);
$content = str_replace(
'{{LANDINGSMALL}}',
trim(config('larecipe.docs.landing'), '/'),
$content
);
return $content;
} | replace stub placeholders.
@return string | generateIndexContent | php | saleem-hadad/larecipe | src/Commands/GenerateDocumentationCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/GenerateDocumentationCommand.php | MIT |
protected function generateLandingContent($stub)
{
return str_replace(
'{{TITLE}}',
ucwords(config('larecipe.docs.landing')),
$stub
);
} | replace stub placeholders.
@return string | generateLandingContent | php | saleem-hadad/larecipe | src/Commands/GenerateDocumentationCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/GenerateDocumentationCommand.php | MIT |
protected function getStub($stub)
{
return $this->filesystem->get(base_path('/vendor/binarytorch/larecipe/stubs/'.$stub.'.stub'));
} | Get the stub file for the generator.
@param $stub
@return string
@throws \Illuminate\Contracts\Filesystem\FileNotFoundException | getStub | php | saleem-hadad/larecipe | src/Commands/GenerateDocumentationCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/GenerateDocumentationCommand.php | MIT |
public function handle()
{
if (! $this->hasValidNameArgument()) {
return;
}
(new Filesystem)->copyDirectory(
__DIR__.'/../../stubs/asset-stubs',
$this->assetPath()
);
// AssetServiceProvider.php replacements...
$this->replace('{{ namespace }}', $this->assetNamespace(), $this->assetPath().'/src/AssetServiceProvider.stub');
$this->replace('{{ component }}', $this->assetName(), $this->assetPath().'/src/AssetServiceProvider.stub');
$this->replace('{{ name }}', $this->assetName(), $this->assetPath().'/src/AssetServiceProvider.stub');
// Asset composer.json replacements...
$this->replace('{{ name }}', $this->argument('name'), $this->assetPath().'/composer.json');
$this->replace('{{ escapedNamespace }}', $this->escapedAssetNamespace(), $this->assetPath().'/composer.json');
// Rename the stubs with the proper file extensions...
$this->renameStubs();
// Register the asset...
$this->addAssetRepositoryToRootComposer();
$this->addAssetPackageToRootComposer();
$this->addScriptsToNpmPackage();
if ($this->confirm("Would you like to install the asset's NPM dependencies?", true)) {
$this->installNpmDependencies();
$this->output->newLine();
}
if ($this->confirm("Would you like to compile the asset's assets?", true)) {
$this->compile();
$this->output->newLine();
}
if ($this->confirm('Would you like to update your Composer packages?', true)) {
$this->composerUpdate();
}
} | Execute the console command.
@return void | handle | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function stubsToRename()
{
return [
$this->assetPath().'/src/AssetServiceProvider.stub',
];
} | Get the array of stubs that need PHP file extensions.
@return array | stubsToRename | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function addAssetRepositoryToRootComposer()
{
$composer = json_decode(file_get_contents(base_path('composer.json')), true);
$composer['repositories'][] = [
'type' => 'path',
'url' => './'.$this->relativeAssetPath(),
];
file_put_contents(
base_path('composer.json'),
json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
} | Add a path repository for the asset to the application's composer.json file.
@return void | addAssetRepositoryToRootComposer | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function addAssetPackageToRootComposer()
{
$composer = json_decode(file_get_contents(base_path('composer.json')), true);
$composer['require'][$this->argument('name')] = '*';
file_put_contents(
base_path('composer.json'),
json_encode($composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
} | Add a package entry for the asset to the application's composer.json file.
@return void | addAssetPackageToRootComposer | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function addScriptsToNpmPackage()
{
$package = json_decode(file_get_contents(base_path('package.json')), true);
$package['scripts']['build-'.$this->assetName()] = 'cd '.$this->relativeAssetPath().' && npm run dev';
$package['scripts']['build-'.$this->assetName().'-prod'] = 'cd '.$this->relativeAssetPath().' && npm run prod';
file_put_contents(
base_path('package.json'),
json_encode($package, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)
);
} | Add a path repository for the asset to the application's composer.json file.
@return void | addScriptsToNpmPackage | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function installNpmDependencies()
{
$this->runProcess('npm set progress=false', $this->assetPath());
$this->runProcess('npm install', $this->assetPath());
} | Install the asset's NPM dependencies.
@return void | installNpmDependencies | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function compile()
{
$this->runProcess('npm run dev', $this->assetPath());
} | Compile the asset's assets.
@return void | compile | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function composerUpdate()
{
$this->runProcess('composer update', getcwd());
} | Update the project's composer dependencies.
@return void | composerUpdate | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function replace($search, $replace, $path)
{
file_put_contents($path, str_replace($search, $replace, file_get_contents($path)));
} | Replace the given string in the given file.
@param string $search
@param string $replace
@param string $path
@return void | replace | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function assetPath()
{
return base_path($this->relativeAssetPath());
} | Get the path to the asset.
@return string | assetPath | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function relativeAssetPath()
{
return config('larecipe.packages.path', 'larecipe-components').'/'.$this->assetClass();
} | Get the relative path to the asset.
@return string | relativeAssetPath | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function assetNamespace()
{
return Str::studly($this->assetVendor()).'\\'.$this->assetClass();
} | Get the asset's namespace.
@return string | assetNamespace | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function escapedAssetNamespace()
{
return str_replace('\\', '\\\\', $this->assetNamespace());
} | Get the asset's escaped namespace.
@return string | escapedAssetNamespace | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function assetClass()
{
return Str::studly($this->assetName());
} | Get the asset's class name.
@return string | assetClass | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function assetVendor()
{
return explode('/', $this->argument('name'))[0];
} | Get the asset's vendor.
@return string | assetVendor | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
protected function assetName()
{
return explode('/', $this->argument('name'))[1];
} | Get the asset's base name.
@return string | assetName | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
public function hasValidNameArgument()
{
$name = $this->argument('name');
if (! Str::contains($name, '/')) {
$this->error("The name argument expects a vendor and name in 'Composer' format. Here's an example: `vendor/name`.");
return false;
}
return true;
} | Determine if the name argument is valid.
@return bool | hasValidNameArgument | php | saleem-hadad/larecipe | src/Commands/AssetCommand.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Commands/AssetCommand.php | MIT |
public function __construct(Filesystem $files, Cache $cache)
{
$this->files = $files;
$this->cache = $cache;
} | Create a new documentation instance.
@param Filesystem $files
@param Cache $cache | __construct | php | saleem-hadad/larecipe | src/Models/Documentation.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Models/Documentation.php | MIT |
public static function replaceLinks($version, $content)
{
$content = str_replace('{{version}}', $version, $content);
$content = str_replace('{{route}}', trim(config('larecipe.docs.route'), '/'), $content);
$content = str_replace('"#', '"'.request()->getRequestUri().'#', $content);
return $content;
} | Replace the version and route placeholders.
@param string $version
@param string $content
@return string | replaceLinks | php | saleem-hadad/larecipe | src/Models/Documentation.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Models/Documentation.php | MIT |
public function sectionExists($version, $page)
{
return $this->files->exists(
base_path(config('larecipe.docs.path').'/'.$version.'/'.$page.'.md')
);
} | Check if the given section exists.
@param string $version
@param string $page
@return bool | sectionExists | php | saleem-hadad/larecipe | src/Models/Documentation.php | https://github.com/saleem-hadad/larecipe/blob/master/src/Models/Documentation.php | MIT |
protected function getPackageProviders($app)
{
return [LaRecipeServiceProvider::class];
} | @param \Illuminate\Foundation\Application $app
@return array | getPackageProviders | php | saleem-hadad/larecipe | tests/TestCase.php | https://github.com/saleem-hadad/larecipe/blob/master/tests/TestCase.php | MIT |
protected function getEnvironmentSetUp($app)
{
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
} | Define environment setup.
@param \Illuminate\Foundation\Application $app
@return void | getEnvironmentSetUp | php | saleem-hadad/larecipe | tests/TestCase.php | https://github.com/saleem-hadad/larecipe/blob/master/tests/TestCase.php | MIT |
protected function getPackageAliases($app)
{
return [
'LaRecipe' => LaRecipe::class,
];
} | Load package alias
@param \Illuminate\Foundation\Application $app
@return array | getPackageAliases | php | saleem-hadad/larecipe | tests/TestCase.php | https://github.com/saleem-hadad/larecipe/blob/master/tests/TestCase.php | MIT |
public function __construct(
$host,
$user,
$pass,
$port = null,
$ssl = false,
$tls = false
) {
Argument::i()
->test(1, 'string')
->test(2, 'string')
->test(3, 'string')
->test(4, 'int', 'null')
->test(5, 'bool')
->test(6, 'bool');
if (is_null($port)) {
$port = $ssl ? 995 : 110;
}
$this->host = $host;
$this->username = $user;
$this->password = $pass;
$this->port = $port;
$this->ssl = $ssl;
$this->tls = $tls;
$this->connect();
} | Constructor - Store connection information
@param *string $host The POP3 host
@param *string $user The mailbox user name
@param *string $pass The mailbox password
@param int|null $port The POP3 port
@param bool $ssl Whether to use SSL
@param bool $tls Whether to use TLS | __construct | php | Eden-PHP/Mail | src/Pop3.php | https://github.com/Eden-PHP/Mail/blob/master/src/Pop3.php | MIT |
public function connect($test = false)
{
Argument::i()->test(1, 'bool');
if ($this->loggedin) {
return $this;
}
$host = $this->host;
if ($this->ssl) {
$host = 'ssl://' . $host;
}
$errno = 0;
$errstr = '';
$this->socket = fsockopen($host, $this->port, $errno, $errstr, self::TIMEOUT);
if (!$this->socket) {
//throw exception
Exception::i()
->setMessage(Exception::SERVER_ERROR)
->addVariable($host.':'.$this->port)
->trigger();
}
$welcome = $this->receive();
strtok($welcome, '<');
$this->timestamp = strtok('>');
if (!strpos($this->timestamp, '@')) {
$this->timestamp = null;
} else {
$this->timestamp = '<' . $this->timestamp . '>';
}
if ($this->tls) {
$this->call('STLS');
if (!stream_socket_enable_crypto(
$this->socket,
true,
STREAM_CRYPTO_METHOD_TLS_CLIENT
)) {
$this->disconnect();
//throw exception
Exception::i()
->setMessage(Exception::TLS_ERROR)
->addVariable($host.':'.$this->port)
->trigger();
}
}
if ($test) {
$this->disconnect();
return $this;
}
//login
if ($this->timestamp) {
try {
$this->call(
'APOP '.$this->username
. ' '
. md5($this->timestamp . $this->password)
);
return;
} catch (Argument $e) {
// ignore
}
}
$this->call('USER '.$this->username);
$this->call('PASS '.$this->password);
$this->loggedin = true;
return $this;
} | Connects to the server
@param bool $test Whether to output the logs
@return Eden\Mail\Pop3 | connect | php | Eden-PHP/Mail | src/Pop3.php | https://github.com/Eden-PHP/Mail/blob/master/src/Pop3.php | MIT |
public function disconnect()
{
if (!$this->socket) {
return $this;
}
try {
$this->send('QUIT');
} catch (Argument $e) {
// ignore error - we're closing the socket anyway
}
fclose($this->socket);
$this->socket = null;
return $this;
} | Disconnects from the server
@return Eden\Mail\Pop3 | disconnect | php | Eden-PHP/Mail | src/Pop3.php | https://github.com/Eden-PHP/Mail/blob/master/src/Pop3.php | MIT |
public function getEmails($start = 0, $range = 10)
{
Argument::i()
->test(1, 'int')
->test(2, 'int');
$total = $this->getEmailTotal();
if ($total == 0) {
return array();
}
if (!is_array($start)) {
$range = $range > 0 ? $range : 1;
$start = $start >= 0 ? $start : 0;
$max = $total - $start;
if ($max < 1) {
$max = $total;
}
$min = $max - $range + 1;
if ($min < 1) {
$min = 1;
}
$set = $min . ':' . $max;
if ($min == $max) {
$set = $min;
}
}
$emails = array();
for ($i = $min; $i <= $max; $i++) {
$emails[] = $this->getEmailFormat($this->call('RETR '.$i, true));
}
return $emails;
} | Returns a list of emails given the range
@param number $start Pagination start
@param number $range Pagination range
@return array | getEmails | php | Eden-PHP/Mail | src/Pop3.php | https://github.com/Eden-PHP/Mail/blob/master/src/Pop3.php | MIT |
public function getEmailTotal()
{
@list($messages, $octets) = explode(' ', $this->call('STAT'));
$messages = is_numeric($messages) ? $messages : 0;
return $messages;
} | Returns the total number of emails in a mailbox
@return number | getEmailTotal | php | Eden-PHP/Mail | src/Pop3.php | https://github.com/Eden-PHP/Mail/blob/master/src/Pop3.php | MIT |
protected function call($command, $multiline = false)
{
if (!$this->send($command)) {
return false;
}
return $this->receive($multiline);
} | Send it out and return the response
@param *string $command The raw POP3 command
@param bool $multiline Whether to expect a multiline response
@return string|false | call | php | Eden-PHP/Mail | src/Pop3.php | https://github.com/Eden-PHP/Mail/blob/master/src/Pop3.php | MIT |
protected function receive($multiline = false)
{
$result = @fgets($this->socket);
$status = $result = trim($result);
$message = '';
if (strpos($result, ' ')) {
list($status, $message) = explode(' ', $result, 2);
}
if ($status != '+OK') {
return false;
}
if ($multiline) {
$message = '';
$line = fgets($this->socket);
while ($line && rtrim($line, "\r\n") != '.') {
if ($line[0] == '.') {
$line = substr($line, 1);
}
$this->debug('Receiving: '.$line);
$message .= $line;
$line = fgets($this->socket);
};
}
return $message;
} | Returns the response when all of it is received
@param bool $multiline Whether to expect a multiline response
@return string | receive | php | Eden-PHP/Mail | src/Pop3.php | https://github.com/Eden-PHP/Mail/blob/master/src/Pop3.php | MIT |
protected function send($command)
{
$this->debug('Sending: '.$command);
return fputs($this->socket, $command . "\r\n");
} | Sends out the command
@param *string $command The raw POP3 command
@return bool | send | php | Eden-PHP/Mail | src/Pop3.php | https://github.com/Eden-PHP/Mail/blob/master/src/Pop3.php | MIT |
private function debug($string)
{
if ($this->debugging) {
$string = htmlspecialchars($string);
echo '<pre>'.$string.'</pre>'."\n";
}
return $this;
} | Debugging
@param *string $string The string to output
@return Eden\Mail\Imap | debug | php | Eden-PHP/Mail | src/Pop3.php | https://github.com/Eden-PHP/Mail/blob/master/src/Pop3.php | MIT |
public function __construct(
$host,
$user,
$pass,
$port = null,
$ssl = false,
$tls = false
) {
Argument::i()
->test(1, 'string')
->test(2, 'string')
->test(3, 'string')
->test(4, 'int', 'null')
->test(5, 'bool')
->test(6, 'bool');
if (is_null($port)) {
$port = $ssl ? 465 : 25;
}
$this->host = $host;
$this->username = $user;
$this->password = $pass;
$this->port = $port;
$this->ssl = $ssl;
$this->tls = $tls;
$this->boundary[] = md5(time().'1');
$this->boundary[] = md5(time().'2');
} | Constructor - Store connection information
@param *string $host The SMTP host
@param *string $user The mailbox user name
@param *string $pass The mailbox password
@param int|null $port The SMTP port
@param bool $ssl Whether to use SSL
@param bool $tls Whether to use TLS | __construct | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
public function addAttachment($filename, $data, $mime = null)
{
Argument::i()
->test(1, 'string')
->test(2, 'string')
->test(3, 'string', 'null');
$this->attachments[] = array($filename, $data, $mime);
return $this;
} | Adds an attachment to the email
@param *string $filename The name of the file
@param *string $data The file data
@param string $mime The mime type
@return Eden\Mail\Smtp | addAttachment | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
public function addBCC($email, $name = null)
{
Argument::i()
->test(1, 'string')
->test(2, 'string', 'null');
$this->bcc[$email] = $name;
return $this;
} | Adds an email to the bcc list
@param *string $email Email address
@param string $name Name of person
@return Eden\Mail\Smtp | addBCC | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
public function addCC($email, $name = null)
{
Argument::i()
->test(1, 'string')
->test(2, 'string', 'null');
$this->cc[$email] = $name;
return $this;
} | Adds an email to the cc list
@param *string $email Email address
@param string $name Name of person
@return Eden\Mail\Smtp | addCC | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
public function addTo($email, $name = null)
{
Argument::i()
->test(1, 'string')
->test(2, 'string', 'null');
$this->to[$email] = $name;
return $this;
} | Adds an email to the to list
@param *string $email Email address
@param string $name Name of person
@return Eden\Mail\Smtp | addTo | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
public function connect($timeout = self::TIMEOUT, $test = false)
{
Argument::i()
->test(1, 'int')
->test(2, 'bool');
$host = $this->host;
if ($this->ssl) {
$host = 'ssl://' . $host;
} else {
$host = 'tcp://' . $host;
}
$errno = 0;
$errstr = '';
$this->socket = @stream_socket_client($host.':'.$this->port, $errno, $errstr, $timeout);
if (!$this->socket || strlen($errstr) > 0 || $errno > 0) {
//throw exception
Exception::i()
->setMessage(Exception::SERVER_ERROR)
->addVariable($host.':'.$this->port)
->trigger();
}
$this->receive();
if (!$this->call('EHLO '.$_SERVER['HTTP_HOST'], 250)
&& !$this->call('HELO '.$_SERVER['HTTP_HOST'], 250)) {
$this->disconnect();
//throw exception
Exception::i()
->setMessage(Exception::SERVER_ERROR)
->addVariable($host.':'.$this->port)
->trigger();
}
if ($this->tls && !$this->call('STARTTLS', 220, 250)) {
if (!stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
$this->disconnect();
//throw exception
Exception::i()
->setMessage(Exception::TLS_ERROR)
->addVariable($host.':'.$this->port)
->trigger();
}
if (!$this->call('EHLO '.$_SERVER['HTTP_HOST'], 250)
&& !$this->call('HELO '.$_SERVER['HTTP_HOST'], 250)) {
$this->disconnect();
//throw exception
Exception::i()
->setMessage(Exception::SERVER_ERROR)
->addVariable($host.':'.$this->port)
->trigger();
}
}
if ($test) {
$this->disconnect();
return $this;
}
//login
if (!$this->call('AUTH LOGIN', 250, 334)) {
$this->disconnect();
//throw exception
Exception::i(Exception::LOGIN_ERROR)->trigger();
}
if (!$this->call(base64_encode($this->username), 334)) {
$this->disconnect();
//throw exception
Exception::i()->setMessage(Exception::LOGIN_ERROR);
}
if (!$this->call(base64_encode($this->password), 235, 334)) {
$this->disconnect();
//throw exception
Exception::i()->setMessage(Exception::LOGIN_ERROR);
}
return $this;
} | Connects to the server
@param int $timeout The connection timeout
@param bool $test Whether to output the logs
@return Eden\Mail\Smtp | connect | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
public function disconnect()
{
if ($this->socket) {
$this->push('QUIT');
fclose($this->socket);
$this->socket = null;
}
return $this;
} | Disconnects from the server
@return Eden\Mail\Smtp | disconnect | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
public function reset()
{
$this->subject = null;
$this->body = array();
$this->to = array();
$this->cc = array();
$this->bcc = array();
$this->attachments = array();
$this->disconnect();
return $this;
} | Resets the class
@return Eden\Mail\Smtp | reset | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
public function setBody($body, $html = false)
{
Argument::i()
->test(1, 'string')
->test(2, 'bool');
if ($html) {
$this->body['text/html'] = $body;
$body = strip_tags($body);
}
$this->body['text/plain'] = $body;
return $this;
} | Sets body
@param *string $body The raw body
@param bool $html Is this an html body?
@return Eden\Mail\Smtp | setBody | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
public function setSubject($subject)
{
Argument::i()->test(1, 'string');
$this->subject = $subject;
return $this;
} | Sets subject
@param string $subject The title of this message
@return Eden\Mail\Smtp | setSubject | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
protected function call($command, $code = null)
{
if (!$this->push($command)) {
return false;
}
$receive = $this->receive();
$args = func_get_args();
if (count($args) > 1) {
for ($i = 1; $i < count($args); $i++) {
if (strpos($receive, (string)$args[$i]) === 0) {
return true;
}
}
return false;
}
return $receive;
} | Send it out and return the response
@param *string $command The raw SMTP command
@param int|null $code The command code
@return string|false | call | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
protected function getAlternativeAttachmentBody()
{
$alternative = $this->getAlternativeBody();
$body = array();
$body[] = 'Content-Type: multipart/mixed; boundary="'.$this->boundary[1].'"';
$body[] = null;
$body[] = '--'.$this->boundary[1];
foreach ($alternative as $line) {
$body[] = $line;
}
return $this->addAttachmentBody($body);
} | Adds the attachment string body
for HTML formatted emails
@return array | getAlternativeAttachmentBody | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
protected function getAlternativeBody()
{
$plain = $this->getPlainBody();
$html = $this->getHtmlBody();
$body = array();
$body[] = 'Content-Type: multipart/alternative; boundary="'.$this->boundary[0].'"';
$body[] = null;
$body[] = '--'.$this->boundary[0];
foreach ($plain as $line) {
$body[] = $line;
}
$body[] = '--'.$this->boundary[0];
foreach ($html as $line) {
$body[] = $line;
}
$body[] = '--'.$this->boundary[0].'--';
$body[] = null;
$body[] = null;
return $body;
} | Adds the string body
for HTML formatted emails
@return array | getAlternativeBody | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
protected function getBody()
{
$type = 'Plain';
if (count($this->body) > 1) {
$type = 'Alternative';
} else if (isset($this->body['text/html'])) {
$type = 'Html';
}
$method = 'get%sBody';
if (!empty($this->attachments)) {
$method = 'get%sAttachmentBody';
}
$method = sprintf($method, $type);
return $this->$method();
} | Returns the body
@return array | getBody | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
protected function getHtmlAttachmentBody()
{
$html = $this->getHtmlBody();
$body = array();
$body[] = 'Content-Type: multipart/mixed; boundary="'.$this->boundary[1].'"';
$body[] = null;
$body[] = '--'.$this->boundary[1];
foreach ($html as $line) {
$body[] = $line;
}
return $this->addAttachmentBody($body);
} | Returns the HTML + Attachment version body
@return array | getHtmlAttachmentBody | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
protected function getHtmlBody()
{
$charset = $this->isUtf8($this->body['text/html']) ? 'utf-8' : 'US-ASCII';
$html = str_replace("\r", '', trim($this->body['text/html']));
$encoded = explode("\n", $this->quotedPrintableEncode($html));
$body = array();
$body[] = 'Content-Type: text/html; charset='.$charset;
$body[] = 'Content-Transfer-Encoding: quoted-printable'."\n";
foreach ($encoded as $line) {
$body[] = $line;
}
$body[] = null;
$body[] = null;
return $body;
} | Returns the HTML version body
@return array | getHtmlBody | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
protected function getPlainAttachmentBody()
{
$plain = $this->getPlainBody();
$body = array();
$body[] = 'Content-Type: multipart/mixed; boundary="'.$this->boundary[1].'"';
$body[] = null;
$body[] = '--'.$this->boundary[1];
foreach ($plain as $line) {
$body[] = $line;
}
return $this->addAttachmentBody($body);
} | Returns the Plain + Attachment version body
@return array | getPlainAttachmentBody | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
protected function getPlainBody()
{
$charset = $this->isUtf8($this->body['text/plain']) ? 'utf-8' : 'US-ASCII';
$plane = str_replace("\r", '', trim($this->body['text/plain']));
$count = ceil(strlen($plane) / 998);
$body = array();
$body[] = 'Content-Type: text/plain; charset='.$charset;
$body[] = 'Content-Transfer-Encoding: 7bit';
$body[] = null;
for ($i = 0; $i < $count; $i++) {
$body[] = substr($plane, ($i * 998), 998);
}
$body[] = null;
$body[] = null;
return $body;
} | Returns the Plain version body
@return array | getPlainBody | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
protected function receive()
{
$data = '';
$now = time();
while ($str = fgets($this->socket, 1024)) {
$data .= $str;
if (substr($str, 3, 1) == ' ' || time() > ($now + self::TIMEOUT)) {
break;
}
}
$this->debug('Receiving: '. $data);
return $data;
} | Returns the response when all of it is received
@return string | receive | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
protected function push($command)
{
$this->debug('Sending: '.$command);
return fwrite($this->socket, $command . "\r\n");
} | Sends out the command
@param *string $command The raw SMTP command
@return bool | push | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
private function debug($string)
{
if ($this->debugging) {
$string = htmlspecialchars($string);
echo '<pre>'.$string.'</pre>'."\n";
}
return $this;
} | Debugging
@param *string $string The string to output
@return Eden\Mail\Smtp | debug | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
private function getTimestamp()
{
$zone = date('Z');
$sign = ($zone < 0) ? '-' : '+';
$zone = abs($zone);
$zone = (int)($zone / 3600) * 100 + ($zone % 3600) / 60;
return sprintf("%s %s%04d", date('D, j M Y H:i:s'), $sign, $zone);
} | Returns timestamp, formatted to what SMTP expects
@return string | getTimestamp | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
private function isUtf8($string)
{
$regex = array(
'[\xC2-\xDF][\x80-\xBF]',
'\xE0[\xA0-\xBF][\x80-\xBF]',
'[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}',
'\xED[\x80-\x9F][\x80-\xBF]',
'\xF0[\x90-\xBF][\x80-\xBF]{2}',
'[\xF1-\xF3][\x80-\xBF]{3}',
'\xF4[\x80-\x8F][\x80-\xBF]{2}');
$count = ceil(strlen($string) / 5000);
for ($i = 0; $i < $count; $i++) {
if (preg_match('%(?:'. implode('|', $regex).')+%xs', substr($string, ($i * 5000), 5000))) {
return false;
}
}
return true;
} | Returns true if there's UTF encodeing
@param *string The string to test
@return bool | isUtf8 | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
private function quotedPrintableEncode($input, $line_max = 250)
{
$hex = array('0','1','2','3','4','5','6','7',
'8','9','A','B','C','D','E','F');
$lines = preg_split("/(?:\r\n|\r|\n)/", $input);
$linebreak = "=0D=0A=\r\n";
/* the linebreak also counts as characters in the mime_qp_long_line
* rule of spam-assassin */
$line_max = $line_max - strlen($linebreak);
$escape = "=";
$output = "";
$cur_conv_line = "";
$length = 0;
$whitespace_pos = 0;
$addtl_chars = 0;
// iterate lines
for ($j = 0; $j < count($lines); $j++) {
$line = $lines[$j];
$linlen = strlen($line);
// iterate chars
for ($i = 0; $i < $linlen; $i++) {
$c = substr($line, $i, 1);
$dec = ord($c);
$length++;
if ($dec == 32) {
// space occurring at end of line, need to encode
if (($i == ($linlen - 1))) {
$c = "=20";
$length += 2;
}
$addtl_chars = 0;
$whitespace_pos = $i;
} else if (($dec == 61) || ($dec < 32 ) || ($dec > 126)) {
$h2 = floor($dec/16);
$h1 = floor($dec%16);
$c = $escape . $hex["$h2"] . $hex["$h1"];
$length += 2;
$addtl_chars += 2;
}
// length for wordwrap exceeded, get a newline into the text
if ($length >= $line_max) {
$cur_conv_line .= $c;
// read only up to the whitespace for the current line
$whitesp_diff = $i - $whitespace_pos + $addtl_chars;
//the text after the whitespace will have to be read
// again ( + any additional characters that came into
// existence as a result of the encoding process after the whitespace)
//
// Also, do not start at 0, if there was *no* whitespace in
// the whole line
if (($i + $addtl_chars) > $whitesp_diff) {
$output .= substr($cur_conv_line, 0, (strlen($cur_conv_line) -
$whitesp_diff)) . $linebreak;
$i = $i - $whitesp_diff + $addtl_chars;
} else {
$output .= $cur_conv_line . $linebreak;
}
$cur_conv_line = "";
$length = 0;
$whitespace_pos = 0;
} else {
// length for wordwrap not reached, continue reading
$cur_conv_line .= $c;
}
} // end of for
$length = 0;
$whitespace_pos = 0;
$output .= $cur_conv_line;
$cur_conv_line = "";
if ($j<=count($lines)-1) {
$output .= $linebreak;
}
} // end for
return trim($output);
} | Returns a printable encode version of the body
@param *string $input The string to encode
@param int $line_max line length
@return string | quotedPrintableEncode | php | Eden-PHP/Mail | src/Smtp.php | https://github.com/Eden-PHP/Mail/blob/master/src/Smtp.php | MIT |
public function __construct(
$host,
$user,
$pass,
$port = null,
$ssl = false,
$tls = false
) {
Argument::i()
->test(1, 'string')
->test(2, 'string')
->test(3, 'string')
->test(4, 'int', 'null')
->test(5, 'bool')
->test(6, 'bool');
if (is_null($port)) {
$port = $ssl ? 993 : 143;
}
$this->host = $host;
$this->username = $user;
$this->password = $pass;
$this->port = $port;
$this->ssl = $ssl;
$this->tls = $tls;
} | Constructor - Store connection information
@param *string $host The IMAP host
@param *string $user The mailbox user name
@param *string $pass The mailbox password
@param int|null $port The IMAP port
@param bool $ssl Whether to use SSL
@param bool $tls Whether to use TLS | __construct | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function connect($timeout = self::TIMEOUT, $test = false)
{
Argument::i()->test(1, 'int')->test(2, 'bool');
if ($this->socket) {
return $this;
}
$host = $this->host;
if ($this->ssl) {
$host = 'ssl://' . $host;
}
$errno = 0;
$errstr = '';
$this->socket = @fsockopen($host, $this->port, $errno, $errstr, $timeout);
if (!$this->socket) {
//throw exception
Exception::i()
->setMessage(Exception::SERVER_ERROR)
->addVariable($host.':'.$this->port)
->trigger();
}
if (strpos($this->getLine(), '* OK') === false) {
$this->disconnect();
//throw exception
Exception::i()
->setMessage(Exception::SERVER_ERROR)
->addVariable($host.':'.$this->port)
->trigger();
}
if ($this->tls) {
$this->send('STARTTLS');
if (!stream_socket_enable_crypto($this->socket, true, STREAM_CRYPTO_METHOD_TLS_CLIENT)) {
$this->disconnect();
//throw exception
Exception::i()
->setMessage(Exception::TLS_ERROR)
->addVariable($host.':'.$this->port)
->trigger();
}
}
if ($test) {
fclose($this->socket);
$this->socket = null;
return $this;
}
//login
$result = $this->call('LOGIN', $this->escape($this->username, $this->password));
if (!is_array($result) || strpos(implode(' ', $result), 'OK') === false) {
$this->disconnect();
//throw exception
Exception::i(Exception::LOGIN_ERROR)->trigger();
}
return $this;
} | Connects to the server
@param int $timeout The connection timeout
@param bool $test Whether to output the logs
@return Eden\Mail\Imap | connect | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function disconnect()
{
if ($this->socket) {
$this->send('CLOSE');
$this->send('LOGOUT');
fclose($this->socket);
$this->socket = null;
}
return $this;
} | Disconnects from the server
@return Eden\Mail\Imap | disconnect | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function getActiveMailbox()
{
return $this->mailbox;
} | Returns the active mailbox
@return string | getActiveMailbox | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function getEmails($start = 0, $range = 10, $body = false)
{
Argument::i()
->test(1, 'int', 'array')
->test(2, 'int');
//if not connected
if (!$this->socket) {
//then connect
$this->connect();
}
//if the total in this mailbox is 0
//it means they probably didn't select a mailbox
//or the mailbox selected is empty
if ($this->total == 0) {
//we might as well return an empty array
return array();
}
//if start is an array
if (is_array($start)) {
//it is a set of numbers
$set = implode(',', $start);
//just ignore the range parameter
} else {
//start is a number
//range must be grater than 0
$range = $range > 0 ? $range : 1;
//start must be a positive number
$start = $start >= 0 ? $start : 0;
//calculate max (ex. 300 - 4 = 296)
$max = $this->total - $start;
//if max is less than 1
if ($max < 1) {
//set max to total (ex. 300)
$max = $this->total;
}
//calculate min (ex. 296 - 15 + 1 = 282)
$min = $max - $range + 1;
//if min less than 1
if ($min < 1) {
//set it to 1
$min = 1;
}
//now add min and max to set (ex. 282:296 or 1 - 300)
$set = $min . ':' . $max;
//if min equal max
if ($min == $max) {
//we should only get one number
$set = $min;
}
}
$items = array('UID', 'FLAGS', 'BODY[HEADER]');
if ($body) {
$items = array('UID', 'FLAGS', 'BODY[]');
}
//now lets call this
$emails = $this->getEmailResponse('FETCH', array($set, $this->getList($items)));
//this will be in ascending order
//we actually want to reverse this
$emails = array_reverse($emails);
return $emails;
} | Returns a list of emails given the range
@param number $start Pagination start
@param number $range Pagination range
@param bool $body add body to threads
@return array | getEmails | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function getEmailTotal()
{
return $this->total;
} | Returns the total number of emails in a mailbox
@return number | getEmailTotal | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function getNextUid()
{
return $this->next;
} | Returns the total number of emails in a mailbox
@return number | getNextUid | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function getUniqueEmails($uid, $body = false)
{
Argument::i()
->test(1, 'int', 'string', 'array')
->test(2, 'bool');
//if not connected
if (!$this->socket) {
//then connect
$this->connect();
}
//if the total in this mailbox is 0
//it means they probably didn't select a mailbox
//or the mailbox selected is empty
if ($this->total == 0) {
//we might as well return an empty array
return array();
}
//if uid is an array
if (is_array($uid)) {
$uid = implode(',', $uid);
}
//lets call it
$items = array('UID', 'FLAGS', 'BODY[HEADER]');
if ($body) {
$items = array('UID', 'FLAGS', 'BODY[]');
}
$first = is_numeric($uid) ? true : false;
return $this->getEmailResponse('UID FETCH', array($uid, $this->getList($items)), $first);
} | Returns a list of emails given a uid or set of uids
@param *number|array $uid A list of uid/s
@param bool $body Whether to also include the body
@return array | getUniqueEmails | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function move($uid, $mailbox)
{
Argument::i()->test(1, 'int', 'string')->test(2, 'string');
if (!$this->socket) {
$this->connect();
}
return $this->call('UID MOVE '.$uid.' '.$mailbox);
} | Moves an email from folder to other folder
@param *number $uid The mail unique ID
@param *string $mailbox The mailbox destination
@return Eden\Mail\Imap | move | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function copy($uid, $mailbox)
{
Argument::i()->test(1, 'int', 'string')->test(2, 'string');
if (!$this->socket) {
$this->connect();
}
$this->call('UID COPY '.$uid.' '.$mailbox);
return $this->remove($uid);
} | Copy an email to another mailbox
@param *number $uid The mail unique ID
@param *string $mailbox The mailbox destination
@return Eden\Mail\Imap | copy | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function remove($uid)
{
Argument::i()->test(1, 'int', 'string');
if (!$this->socket) {
$this->connect();
}
$this->call('UID STORE '.$uid.' FLAGS.SILENT \Deleted');
return $this;
} | Remove an email from a mailbox
@param *number $uid The mail UID to remove
@return Eden\Mail\Imap | remove | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function expunge()
{
$this->call('expunge');
return $this;
} | Remove an email from a mailbox
@return Eden\Mail\Imap | expunge | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function search(
array $filter,
$start = 0,
$range = 10,
$or = false,
$body = false
) {
Argument::i()
->test(2, 'int')
->test(3, 'int')
->test(4, 'bool')
->test(5, 'bool');
if (!$this->socket) {
$this->connect();
}
//build a search criteria
$search = $not = array();
foreach ($filter as $where) {
if (is_string($where)) {
$search[] = $where;
continue;
}
if ($where[0] == 'NOT') {
$not = $where[1];
continue;
}
$item = $where[0].' "'.$where[1].'"';
if (isset($where[2])) {
$item .= ' "'.$where[2].'"';
}
$search[] = $item;
}
//if this is an or search
if ($or && count($search) > 1) {
//item1
//OR (item1) (item2)
//OR (item1) (OR (item2) (item3))
//OR (item1) (OR (item2) (OR (item3) (item4)))
$query = null;
while ($item = array_pop($search)) {
if (is_null($query)) {
$query = $item;
} else if (strpos($query, 'OR') !== 0) {
$query = 'OR ('.$query.') ('.$item.')';
} else {
$query = 'OR ('.$item.') ('.$query.')';
}
}
$search = $query;
} else {
//this is an and search
$search = implode(' ', $search);
}
//do the search
$response = $this->call('UID SEARCH '.$search);
//get the result
$result = array_pop($response);
//if we got some results
if (strpos($result, 'OK') !== false) {
//parse out the uids
$uids = explode(' ', $response[0]);
array_shift($uids);
array_shift($uids);
foreach ($uids as $i => $uid) {
if (in_array($uid, $not)) {
unset($uids[$i]);
}
}
if (empty($uids)) {
return array();
}
$uids = array_reverse($uids);
//pagination
$count = 0;
foreach ($uids as $i => $id) {
if ($i < $start) {
unset($uids[$i]);
continue;
}
$count ++;
if ($range != 0 && $count > $range) {
unset($uids[$i]);
continue;
}
}
//return the email details for this
return $this->getUniqueEmails($uids, $body);
}
//it's not okay just return an empty set
return array();
} | Searches a mailbox for specific emails
@param *array $filter Search filters
@param number $start Results start
@param number $range Results range
@param bool $or Is this an OR search ?
@param bool $body Whether to include the body
@return array | search | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function searchTotal(array $filter, $or = false)
{
Argument::i()->test(2, 'bool');
if (!$this->socket) {
$this->connect();
}
//build a search criteria
$search = array();
foreach ($filter as $where) {
$item = $where[0].' "'.$where[1].'"';
if (isset($where[2])) {
$item .= ' "'.$where[2].'"';
}
$search[] = $item;
}
//if this is an or search
if ($or) {
$search = 'OR ('.implode(') (', $search).')';
} else {
//this is an and search
$search = implode(' ', $search);
}
$response = $this->call('UID SEARCH '.$search);
//get the result
$result = array_pop($response);
//if we got some results
if (strpos($result, 'OK') !== false) {
//parse out the uids
$uids = explode(' ', $response[0]);
array_shift($uids);
array_shift($uids);
return count($uids);
}
//it's not okay just return 0
return 0;
} | Returns the total amount of emails
@param *array $filter Search filters
@param bool $or Is this an OR search ?
@return number | searchTotal | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
public function setActiveMailbox($mailbox)
{
Argument::i()->test(1, 'string');
if (!$this->socket) {
$this->connect();
}
$response = $this->call('SELECT', $this->escape($mailbox));
$result = array_pop($response);
foreach ($response as $line) {
if (strpos($line, 'EXISTS') !== false) {
list($star, $this->total, $type) = explode(' ', $line, 3);
} else if (strpos($line, 'UIDNEXT') !== false) {
list($star, $ok, $next, $this->next, $type) = explode(' ', $line, 5);
$this->next = substr($this->next, 0, -1);
}
if ($this->total && $this->next) {
break;
}
}
if (strpos($result, 'OK') !== false) {
$this->mailbox = $mailbox;
return $this;
}
return false;
} | IMAP requires setting an active mailbox
before getting a list of mails
@param string $mailbox Name of mailbox
@return false|Eden\Mail\Imap | setActiveMailbox | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
protected function getLine()
{
$line = fgets($this->socket);
if ($line === false) {
$this->disconnect();
}
$this->debug('Receiving: '.$line);
return $line;
} | Returns the response one line at a time
@return string | getLine | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
protected function receive($sentTag)
{
$this->buffer = array();
$start = time();
while (time() < ($start + self::TIMEOUT)) {
list($receivedTag, $line) = explode(' ', $this->getLine(), 2);
$this->buffer[] = trim($receivedTag . ' ' . $line);
if ($receivedTag == 'TAG'.$sentTag) {
return $this->buffer;
}
}
return null;
} | Returns the response when all of it is received
@param string $sentTag The custom tag to look for
@return string | receive | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
private function debug($string)
{
if ($this->debugging) {
$string = htmlspecialchars($string);
echo '<pre>'.$string.'</pre>'."\n";
}
return $this;
} | Debugging
@param *string $string The string to output
@return Eden\Mail\Imap | debug | php | Eden-PHP/Mail | src/Imap.php | https://github.com/Eden-PHP/Mail/blob/master/src/Imap.php | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.