Code Duplication    Length = 43-44 lines in 2 locations

api/src/Mailer.php 2 locations

@@ 829-872 (lines=44) @@
826
	/**
827
	 * Parse base-part into _body, _htmlBody, _alternativBody and _parts to eg. add further attachments
828
	 */
829
	function parseBasePart()
830
	{
831
		try {
832
			$base = $this->getBasePart();
833
			$plain_id = $base->findBody('plain');
834
			$html_id = $base->findBody('html');
835
836
			// find further alternativ part
837
			if ($base->getType() == 'multipart/alternativ' && count($base) !== ($html_id ? $html_id : $plain_id))
838
			{
839
				$alternativ_id = (string)count($base);
840
			}
841
842
			$this->_body = $this->_htmlBody = $this->_alternativBody = null;
843
			$this->clearParts();
844
845
			foreach($base->partIterator() as $part)
846
			{
847
				$id = $part->getMimeId();
848
				//error_log(__METHOD__."() plain=$plain_id, html=$html_id: $id: ".$part->getType());
849
				switch($id)
850
				{
851
					case '0':	// base-part itself
852
						continue 2;
853
					case $plain_id:
854
						$this->_body = $part;
855
						break;
856
					case $html_id:
857
						$this->_htmlBody = $part;
858
						break;
859
					case $alternativ_id:
860
						$this->_alternativBody = $part;
861
						break;
862
					default:
863
						$this->_parts[] = $part;
864
				}
865
			}
866
			$this->setBasePart(null);
867
		}
868
		catch (\Exception $e) {
869
			// ignore that there is no base-part yet, so nothing to do
870
			unset($e);
871
		}
872
	}
873
874
	/**
875
	 * clearAttachments, does the same as parseBasePart, but does not add possible attachments
@@ 877-919 (lines=43) @@
874
	/**
875
	 * clearAttachments, does the same as parseBasePart, but does not add possible attachments
876
	 */
877
	function ClearAttachments()
878
	{
879
		try {
880
			$base = $this->getBasePart();
881
			$plain_id = $base->findBody('plain');
882
			$html_id = $base->findBody('html');
883
884
			// find further alternativ part
885
			if ($base->getType() == 'multipart/alternativ' && count($base) !== ($html_id ? $html_id : $plain_id))
886
			{
887
				$alternativ_id = (string)count($base);
888
			}
889
890
			$this->_body = $this->_htmlBody = $this->_alternativBody = null;
891
			$this->clearParts();
892
893
			foreach($base->partIterator() as $part)
894
			{
895
				$id = $part->getMimeId();
896
				//error_log(__METHOD__."() plain=$plain_id, html=$html_id: $id: ".$part->getType());
897
				switch($id)
898
				{
899
					case '0':	// base-part itself
900
						continue 2;
901
					case $plain_id:
902
						$this->_body = $part;
903
						break;
904
					case $html_id:
905
						$this->_htmlBody = $part;
906
						break;
907
					case $alternativ_id:
908
						$this->_alternativBody = $part;
909
						break;
910
					default:
911
				}
912
			}
913
			$this->setBasePart(null);
914
		}
915
		catch (\Exception $e) {
916
			// ignore that there is no base-part yet, so nothing to do
917
			unset($e);
918
		}
919
	}
920
921
	/**
922
	 * Adds a MIME message part.