diff --git a/Sources/Post.php b/Sources/Post.php
index d6ee68c..c019ee3 100644
--- a/Sources/Post.php
+++ b/Sources/Post.php
@@ -18,6 +18,9 @@ if (!defined('SMF'))
 	new topics, quotes, and modifications to existing posts.  It also handles
 	quoting posts by way of javascript.
 
+	void filterNestedQuotes()
+		- removes nested quotes with nesting level more than $options["max_nested_quotes"]
+
 	void Post()
 		- handles showing the post screen, loading the post to be modified, and
 		  loading any post quoted.
@@ -80,6 +83,39 @@ if (!defined('SMF'))
 		// !!!
 */
 
+function filterNestedQuotes(&$message) {
+	global $options;
+	$nesting_level = 0;
+	$message_new = "";
+	$offs = 0;
+	$max_level = intval($options["max_nested_quotes"]);
+	while ($offs<strlen($message)) {
+		preg_match('~(\n?\[quote.*?\])|(\[/quote\]\n?)~i', $message, $match, PREG_OFFSET_CAPTURE, $offs);
+		if (!$match)
+			break;
+		$new_offs = $match[0][1];
+		if ($nesting_level <= $max_level)
+			$message_new .= substr($message, $offs, $new_offs-$offs);
+
+		if (isset($match[1]) && $match[1][0]) {
+			if ($nesting_level == $max_level && strlen($message_new) > 0)
+				$message_new .= "\n";
+			$nesting_level++;
+		}
+
+		if ($nesting_level <= $max_level)
+			$message_new .= $match[0][0];
+
+		$offs = $new_offs + strlen($match[0][0]);
+
+		if (isset($match[2]) && $match[2][0])
+			$nesting_level--;
+	}
+	if ($offs>0) {
+		$message = $message_new . substr($message, $offs);
+	}
+}
+
 function Post()
 {
 	global $txt, $scripturl, $topic, $modSettings, $board;
@@ -860,6 +896,8 @@ function Post()
 			// Remove any nested quotes, if necessary.
 			if (!empty($modSettings['removeNestedQuotes']))
 				$form_message = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $form_message);
+			else
+				filterNestedQuotes($form_message);
 
 			// Add a quote string on the front and end.
 			$form_message = '[quote author=' . $mname . ' link=topic=' . $topic . '.msg' . (int) $_REQUEST['quote'] . '#msg' . (int) $_REQUEST['quote'] . ' date=' . $mdate . ']' . "\n" . rtrim($form_message) . "\n" . '[/quote]';
@@ -2625,6 +2663,8 @@ function QuoteFast()
 		// Remove any nested quotes.
 		if (!empty($modSettings['removeNestedQuotes']))
 			$row['body'] = preg_replace(array('~\n?\[quote.*?\].+?\[/quote\]\n?~is', '~^\n~', '~\[/quote\]~'), '', $row['body']);
+		else
+			filterNestedQuotes($row['body']);
 
 		// Make the body HTML if need be.
 		if (!empty($_REQUEST['mode']))
diff --git a/Themes/core/Settings.template.php b/Themes/core/Settings.template.php
index db97f50..0b2fda5 100644
--- a/Themes/core/Settings.template.php
+++ b/Themes/core/Settings.template.php
@@ -139,6 +139,11 @@ function template_options()
 			),
 			'default' => true,
 		),
+		array(
+			'id' => 'max_nested_quotes',
+			'label' => $txt['max_nested_quotes'],
+			'default' => 0,
+		),
 		array(
 			'id' => 'display_quick_mod',
 			'label' => $txt['display_quick_mod'],
diff --git a/Themes/default/Profile.template.php b/Themes/default/Profile.template.php
index e97ed52..38a2f11 100644
--- a/Themes/default/Profile.template.php
+++ b/Themes/default/Profile.template.php
@@ -1586,6 +1586,10 @@ function template_profile_theme_settings()
 									<option value="2"', !empty($context['member']['options']['display_quick_mod']) && $context['member']['options']['display_quick_mod'] != 1 ? ' selected="selected"' : '', '>', $txt['display_quick_mod_image'], '</option>
 								</select>
 							</li>
+							<li>
+								<label for="max_nested_quotes">', $txt['max_nested_quotes'], '</label>
+								<input name="default_options[max_nested_quotes]" id="max_nested_quotes" value="', intval($context['member']['options']['max_nested_quotes']), '"/>
+							</li>
 						</ul>
 						<dl>
 							<dd></dd>';
diff --git a/Themes/default/Settings.template.php b/Themes/default/Settings.template.php
index 3126fa0..3452bbf 100644
--- a/Themes/default/Settings.template.php
+++ b/Themes/default/Settings.template.php
@@ -139,6 +139,11 @@ function template_options()
 			),
 			'default' => true,
 		),
+		array(
+			'id' => 'max_nested_quotes',
+			'label' => $txt['max_nested_quotes'],
+			'default' => 0,
+		),
 		array(
 			'id' => 'display_quick_mod',
 			'label' => $txt['display_quick_mod'],
diff --git a/Themes/default/languages/Profile.english.php b/Themes/default/languages/Profile.english.php
index fd9b89f..d4ca2ea 100644
--- a/Themes/default/languages/Profile.english.php
+++ b/Themes/default/languages/Profile.english.php
@@ -286,6 +286,7 @@ $txt['display_quick_reply1'] = 'don\'t show at all';
 $txt['display_quick_reply2'] = 'show, off by default';
 $txt['display_quick_reply3'] = 'show, on by default';
 $txt['display_quick_mod'] = 'Show quick-moderation as ';
+$txt['max_nested_quotes'] = 'Maximum nested quotes: ';
 $txt['display_quick_mod_none'] = 'don\'t show.';
 $txt['display_quick_mod_check'] = 'checkboxes.';
 $txt['display_quick_mod_image'] = 'icons.';
diff --git a/Themes/default/languages/Profile.russian-utf8.php b/Themes/default/languages/Profile.russian-utf8.php
index bb0384d..c137ac3 100644
--- a/Themes/default/languages/Profile.russian-utf8.php
+++ b/Themes/default/languages/Profile.russian-utf8.php
@@ -285,6 +285,7 @@ $txt['display_quick_reply'] = 'Форма быстрого ответа: ';
 $txt['display_quick_reply1'] = 'не показывать';
 $txt['display_quick_reply2'] = 'по умолчанию свернута';
 $txt['display_quick_reply3'] = 'по умолчанию развернута';
+$txt['max_nested_quotes'] = 'Максимум вложенных цитат: ';
 $txt['display_quick_mod'] = 'Быстрое модерирование';
 $txt['display_quick_mod_none'] = 'отключить';
 $txt['display_quick_mod_check'] = 'в виде ячеек';
diff --git a/Themes/default/languages/Profile.ukrainian-utf8.php b/Themes/default/languages/Profile.ukrainian-utf8.php
index 014ecc9..533cca6 100644
--- a/Themes/default/languages/Profile.ukrainian-utf8.php
+++ b/Themes/default/languages/Profile.ukrainian-utf8.php
@@ -285,6 +285,7 @@ $txt['display_quick_reply'] = 'Форма швидкої відповіді: ';
 $txt['display_quick_reply1'] = 'не показувати';
 $txt['display_quick_reply2'] = 'включити за замовчуванням - згорнута';
 $txt['display_quick_reply3'] = 'включити за замовчуванням - розгорнута';
+$txt['max_nested_quotes'] = 'Максимум вкладених цитат: ';
 $txt['display_quick_mod'] = 'Показувати функції швидкого модерування ';
 $txt['display_quick_mod_none'] = 'не показувати';
 $txt['display_quick_mod_check'] = 'сотами';
